Skip to content

Commit

Permalink
Add AP utils (#776)
Browse files Browse the repository at this point in the history
* Update get-proto instructions

* Update autogenerated codecs

* Add Arbiter Pool utils

* Move to utils
  • Loading branch information
abefernan authored Jul 19, 2022
1 parent 184def2 commit 6dfc012
Show file tree
Hide file tree
Showing 21 changed files with 2,808 additions and 3,690 deletions.
21 changes: 17 additions & 4 deletions scripts/proto/get-proto.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/bash
# TODO: get automatically from tgrade repo
# Create a "tgrade" folder with "confio" and "third_party" subfolders.
# "confio" contents come from: https://github.com/confio/tgrade/tree/main/proto/confio
# "third_party" contents come from: https://github.com/confio/tgrade/tree/main/third_party
# TODO: generate new proto automatically with support of context from Tgrade repo
# Steps:
# - Create a tgrade/ folder on the same folder as the codegen.sh and get-proto.sh.
# - Then inside that new tgrade/ folder you need 2 subfolders: confio/ and third_party/.
# **************************************
## 1. src/scripts/proto/get-proto.sh
## 2. src/scripts/proto/codegen.sh
## 3. src/scripts/proto/tgrade/confio/
## 4. src/scripts/proto/tgrade/third_party/
# **************************************

# - Then for 3 and 4 we now need to fill those folders with content:
# - The contents for tgrade/confio/ come from https://github.com/confio/tgrade/tree/main/proto/confio
# - The contents for tgrade/third_party/ come from https://github.com/confio/tgrade/tree/main/third_party

# To clone content - clone the main branch from the Tgrade repo and copy pasting those folders there.
# After you should be able to execute the codegen.sh script by yarn proto command.
85 changes: 48 additions & 37 deletions src/codec/confio/poe/v1beta1/poe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import * as _m0 from "protobufjs/minimal";
import { Coin } from "../../../cosmos/base/v1beta1/coin";

export const protobufPackage = "confio.poe.v1beta1";
Expand All @@ -17,6 +17,8 @@ export enum PoEContractType {
OVERSIGHT_COMMUNITY_PROPOSALS = 7,
COMMUNITY_POOL = 8,
VALIDATOR_VOTING = 9,
ARBITER_POOL = 10,
ARBITER_POOL_VOTING = 11,
UNRECOGNIZED = -1,
}

Expand Down Expand Up @@ -52,6 +54,12 @@ export function poEContractTypeFromJSON(object: any): PoEContractType {
case 9:
case "VALIDATOR_VOTING":
return PoEContractType.VALIDATOR_VOTING;
case 10:
case "ARBITER_POOL":
return PoEContractType.ARBITER_POOL;
case 11:
case "ARBITER_POOL_VOTING":
return PoEContractType.ARBITER_POOL_VOTING;
case -1:
case "UNRECOGNIZED":
default:
Expand Down Expand Up @@ -81,6 +89,10 @@ export function poEContractTypeToJSON(object: PoEContractType): string {
return "COMMUNITY_POOL";
case PoEContractType.VALIDATOR_VOTING:
return "VALIDATOR_VOTING";
case PoEContractType.ARBITER_POOL:
return "ARBITER_POOL";
case PoEContractType.ARBITER_POOL_VOTING:
return "ARBITER_POOL_VOTING";
default:
return "UNKNOWN";
}
Expand All @@ -103,7 +115,9 @@ export interface Params {
minDelegationAmounts: Coin[];
}

const baseParams: object = { historicalEntries: 0, initialValEngagementPoints: Long.UZERO };
function createBaseParams(): Params {
return { historicalEntries: 0, initialValEngagementPoints: Long.UZERO, minDelegationAmounts: [] };
}

export const Params = {
encode(message: Params, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
Expand All @@ -122,8 +136,7 @@ export const Params = {
decode(input: _m0.Reader | Uint8Array, length?: number): Params {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseParams } as Params;
message.minDelegationAmounts = [];
const message = createBaseParams();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
Expand All @@ -145,29 +158,21 @@ export const Params = {
},

fromJSON(object: any): Params {
const message = { ...baseParams } as Params;
message.minDelegationAmounts = [];
if (object.historicalEntries !== undefined && object.historicalEntries !== null) {
message.historicalEntries = Number(object.historicalEntries);
} else {
message.historicalEntries = 0;
}
if (object.initialValEngagementPoints !== undefined && object.initialValEngagementPoints !== null) {
message.initialValEngagementPoints = Long.fromString(object.initialValEngagementPoints);
} else {
message.initialValEngagementPoints = Long.UZERO;
}
if (object.minDelegationAmounts !== undefined && object.minDelegationAmounts !== null) {
for (const e of object.minDelegationAmounts) {
message.minDelegationAmounts.push(Coin.fromJSON(e));
}
}
return message;
return {
historicalEntries: isSet(object.historicalEntries) ? Number(object.historicalEntries) : 0,
initialValEngagementPoints: isSet(object.initialValEngagementPoints)
? Long.fromString(object.initialValEngagementPoints)
: Long.UZERO,
minDelegationAmounts: Array.isArray(object?.minDelegationAmounts)
? object.minDelegationAmounts.map((e: any) => Coin.fromJSON(e))
: [],
};
},

toJSON(message: Params): unknown {
const obj: any = {};
message.historicalEntries !== undefined && (obj.historicalEntries = message.historicalEntries);
message.historicalEntries !== undefined &&
(obj.historicalEntries = Math.round(message.historicalEntries));
message.initialValEngagementPoints !== undefined &&
(obj.initialValEngagementPoints = (message.initialValEngagementPoints || Long.UZERO).toString());
if (message.minDelegationAmounts) {
Expand All @@ -178,27 +183,24 @@ export const Params = {
return obj;
},

fromPartial(object: DeepPartial<Params>): Params {
const message = { ...baseParams } as Params;
fromPartial<I extends Exact<DeepPartial<Params>, I>>(object: I): Params {
const message = createBaseParams();
message.historicalEntries = object.historicalEntries ?? 0;
if (object.initialValEngagementPoints !== undefined && object.initialValEngagementPoints !== null) {
message.initialValEngagementPoints = object.initialValEngagementPoints as Long;
} else {
message.initialValEngagementPoints = Long.UZERO;
}
message.minDelegationAmounts = [];
if (object.minDelegationAmounts !== undefined && object.minDelegationAmounts !== null) {
for (const e of object.minDelegationAmounts) {
message.minDelegationAmounts.push(Coin.fromPartial(e));
}
}
message.initialValEngagementPoints =
object.initialValEngagementPoints !== undefined && object.initialValEngagementPoints !== null
? Long.fromValue(object.initialValEngagementPoints)
: Long.UZERO;
message.minDelegationAmounts = object.minDelegationAmounts?.map((e) => Coin.fromPartial(e)) || [];
return message;
},
};

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined | Long;
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin
? T
: T extends Long
? string | number | Long
: T extends Array<infer U>
? Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U>
Expand All @@ -207,7 +209,16 @@ export type DeepPartial<T> = T extends Builtin
? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin
? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>;

if (_m0.util.Long !== Long) {
_m0.util.Long = Long as any;
_m0.configure();
}

function isSet(value: any): boolean {
return value !== null && value !== undefined;
}
Loading

0 comments on commit 6dfc012

Please sign in to comment.