Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen: add authz types for bank, staking #26

Merged
merged 1 commit into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmjs-types",
"version": "0.4.0",
"version": "0.4.1",
"description": "JS and TS types relating to Protocol Buffers used by Cosmos-SDK and other related projects",
"contributors": [
"Will Clark <willclarktech@users.noreply.github.com>"
Expand Down
2 changes: 2 additions & 0 deletions scripts/codegen-cosmos-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ protoc \
"$COSMOS_SDK_DIR/cosmos/bank/v1beta1/genesis.proto" \
"$COSMOS_SDK_DIR/cosmos/bank/v1beta1/query.proto" \
"$COSMOS_SDK_DIR/cosmos/bank/v1beta1/tx.proto" \
"$COSMOS_SDK_DIR/cosmos/bank/v1beta1/authz.proto" \
"$COSMOS_SDK_DIR/cosmos/base/abci/v1beta1/abci.proto" \
"$COSMOS_SDK_DIR/cosmos/base/kv/v1beta1/kv.proto" \
"$COSMOS_SDK_DIR/cosmos/base/query/v1beta1/pagination.proto" \
Expand Down Expand Up @@ -76,6 +77,7 @@ protoc \
"$COSMOS_SDK_DIR/cosmos/staking/v1beta1/query.proto" \
"$COSMOS_SDK_DIR/cosmos/staking/v1beta1/staking.proto" \
"$COSMOS_SDK_DIR/cosmos/staking/v1beta1/tx.proto" \
"$COSMOS_SDK_DIR/cosmos/staking/v1beta1/authz.proto" \
"$COSMOS_SDK_DIR/cosmos/tx/signing/v1beta1/signing.proto" \
"$COSMOS_SDK_DIR/cosmos/tx/v1beta1/service.proto" \
"$COSMOS_SDK_DIR/cosmos/tx/v1beta1/tx.proto" \
Expand Down
92 changes: 92 additions & 0 deletions src/cosmos/bank/v1beta1/authz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { Coin } from "../../../cosmos/base/v1beta1/coin";

export const protobufPackage = "cosmos.bank.v1beta1";

/**
* SendAuthorization allows the grantee to spend up to spend_limit coins from
* the granter's account.
*
* Since: cosmos-sdk 0.43
*/
export interface SendAuthorization {
spendLimit: Coin[];
}

const baseSendAuthorization: object = {};

export const SendAuthorization = {
encode(message: SendAuthorization, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.spendLimit) {
Coin.encode(v!, writer.uint32(10).fork()).ldelim();
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): SendAuthorization {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseSendAuthorization } as SendAuthorization;
message.spendLimit = [];
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.spendLimit.push(Coin.decode(reader, reader.uint32()));
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): SendAuthorization {
const message = { ...baseSendAuthorization } as SendAuthorization;
message.spendLimit = (object.spendLimit ?? []).map((e: any) => Coin.fromJSON(e));
return message;
},

toJSON(message: SendAuthorization): unknown {
const obj: any = {};
if (message.spendLimit) {
obj.spendLimit = message.spendLimit.map((e) => (e ? Coin.toJSON(e) : undefined));
} else {
obj.spendLimit = [];
}
return obj;
},

fromPartial<I extends Exact<DeepPartial<SendAuthorization>, I>>(object: I): SendAuthorization {
const message = { ...baseSendAuthorization } as SendAuthorization;
message.spendLimit = object.spendLimit?.map((e) => Coin.fromPartial(e)) || [];
return message;
},
};

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>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [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();
}
265 changes: 265 additions & 0 deletions src/cosmos/staking/v1beta1/authz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/* eslint-disable */
import Long from "long";
import _m0 from "protobufjs/minimal";
import { Coin } from "../../../cosmos/base/v1beta1/coin";

export const protobufPackage = "cosmos.staking.v1beta1";

/**
* AuthorizationType defines the type of staking module authorization type
*
* Since: cosmos-sdk 0.43
*/
export enum AuthorizationType {
/** AUTHORIZATION_TYPE_UNSPECIFIED - AUTHORIZATION_TYPE_UNSPECIFIED specifies an unknown authorization type */
AUTHORIZATION_TYPE_UNSPECIFIED = 0,
/** AUTHORIZATION_TYPE_DELEGATE - AUTHORIZATION_TYPE_DELEGATE defines an authorization type for Msg/Delegate */
AUTHORIZATION_TYPE_DELEGATE = 1,
/** AUTHORIZATION_TYPE_UNDELEGATE - AUTHORIZATION_TYPE_UNDELEGATE defines an authorization type for Msg/Undelegate */
AUTHORIZATION_TYPE_UNDELEGATE = 2,
/** AUTHORIZATION_TYPE_REDELEGATE - AUTHORIZATION_TYPE_REDELEGATE defines an authorization type for Msg/BeginRedelegate */
AUTHORIZATION_TYPE_REDELEGATE = 3,
UNRECOGNIZED = -1,
}

export function authorizationTypeFromJSON(object: any): AuthorizationType {
switch (object) {
case 0:
case "AUTHORIZATION_TYPE_UNSPECIFIED":
return AuthorizationType.AUTHORIZATION_TYPE_UNSPECIFIED;
case 1:
case "AUTHORIZATION_TYPE_DELEGATE":
return AuthorizationType.AUTHORIZATION_TYPE_DELEGATE;
case 2:
case "AUTHORIZATION_TYPE_UNDELEGATE":
return AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE;
case 3:
case "AUTHORIZATION_TYPE_REDELEGATE":
return AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE;
case -1:
case "UNRECOGNIZED":
default:
return AuthorizationType.UNRECOGNIZED;
}
}

export function authorizationTypeToJSON(object: AuthorizationType): string {
switch (object) {
case AuthorizationType.AUTHORIZATION_TYPE_UNSPECIFIED:
return "AUTHORIZATION_TYPE_UNSPECIFIED";
case AuthorizationType.AUTHORIZATION_TYPE_DELEGATE:
return "AUTHORIZATION_TYPE_DELEGATE";
case AuthorizationType.AUTHORIZATION_TYPE_UNDELEGATE:
return "AUTHORIZATION_TYPE_UNDELEGATE";
case AuthorizationType.AUTHORIZATION_TYPE_REDELEGATE:
return "AUTHORIZATION_TYPE_REDELEGATE";
default:
return "UNKNOWN";
}
}

/**
* StakeAuthorization defines authorization for delegate/undelegate/redelegate.
*
* Since: cosmos-sdk 0.43
*/
export interface StakeAuthorization {
/**
* max_tokens specifies the maximum amount of tokens can be delegate to a validator. If it is
* empty, there is no spend limit and any amount of coins can be delegated.
*/
maxTokens?: Coin;
/**
* allow_list specifies list of validator addresses to whom grantee can delegate tokens on behalf of granter's
* account.
*/
allowList?: StakeAuthorization_Validators | undefined;
/** deny_list specifies list of validator addresses to whom grantee can not delegate tokens. */
denyList?: StakeAuthorization_Validators | undefined;
/** authorization_type defines one of AuthorizationType. */
authorizationType: AuthorizationType;
}

/** Validators defines list of validator addresses. */
export interface StakeAuthorization_Validators {
address: string[];
}

const baseStakeAuthorization: object = { authorizationType: 0 };

export const StakeAuthorization = {
encode(message: StakeAuthorization, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.maxTokens !== undefined) {
Coin.encode(message.maxTokens, writer.uint32(10).fork()).ldelim();
}
if (message.allowList !== undefined) {
StakeAuthorization_Validators.encode(message.allowList, writer.uint32(18).fork()).ldelim();
}
if (message.denyList !== undefined) {
StakeAuthorization_Validators.encode(message.denyList, writer.uint32(26).fork()).ldelim();
}
if (message.authorizationType !== 0) {
writer.uint32(32).int32(message.authorizationType);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): StakeAuthorization {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseStakeAuthorization } as StakeAuthorization;
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.maxTokens = Coin.decode(reader, reader.uint32());
break;
case 2:
message.allowList = StakeAuthorization_Validators.decode(reader, reader.uint32());
break;
case 3:
message.denyList = StakeAuthorization_Validators.decode(reader, reader.uint32());
break;
case 4:
message.authorizationType = reader.int32() as any;
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): StakeAuthorization {
const message = { ...baseStakeAuthorization } as StakeAuthorization;
message.maxTokens =
object.maxTokens !== undefined && object.maxTokens !== null
? Coin.fromJSON(object.maxTokens)
: undefined;
message.allowList =
object.allowList !== undefined && object.allowList !== null
? StakeAuthorization_Validators.fromJSON(object.allowList)
: undefined;
message.denyList =
object.denyList !== undefined && object.denyList !== null
? StakeAuthorization_Validators.fromJSON(object.denyList)
: undefined;
message.authorizationType =
object.authorizationType !== undefined && object.authorizationType !== null
? authorizationTypeFromJSON(object.authorizationType)
: 0;
return message;
},

toJSON(message: StakeAuthorization): unknown {
const obj: any = {};
message.maxTokens !== undefined &&
(obj.maxTokens = message.maxTokens ? Coin.toJSON(message.maxTokens) : undefined);
message.allowList !== undefined &&
(obj.allowList = message.allowList
? StakeAuthorization_Validators.toJSON(message.allowList)
: undefined);
message.denyList !== undefined &&
(obj.denyList = message.denyList ? StakeAuthorization_Validators.toJSON(message.denyList) : undefined);
message.authorizationType !== undefined &&
(obj.authorizationType = authorizationTypeToJSON(message.authorizationType));
return obj;
},

fromPartial<I extends Exact<DeepPartial<StakeAuthorization>, I>>(object: I): StakeAuthorization {
const message = { ...baseStakeAuthorization } as StakeAuthorization;
message.maxTokens =
object.maxTokens !== undefined && object.maxTokens !== null
? Coin.fromPartial(object.maxTokens)
: undefined;
message.allowList =
object.allowList !== undefined && object.allowList !== null
? StakeAuthorization_Validators.fromPartial(object.allowList)
: undefined;
message.denyList =
object.denyList !== undefined && object.denyList !== null
? StakeAuthorization_Validators.fromPartial(object.denyList)
: undefined;
message.authorizationType = object.authorizationType ?? 0;
return message;
},
};

const baseStakeAuthorization_Validators: object = { address: "" };

export const StakeAuthorization_Validators = {
encode(message: StakeAuthorization_Validators, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.address) {
writer.uint32(10).string(v!);
}
return writer;
},

decode(input: _m0.Reader | Uint8Array, length?: number): StakeAuthorization_Validators {
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = { ...baseStakeAuthorization_Validators } as StakeAuthorization_Validators;
message.address = [];
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.address.push(reader.string());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},

fromJSON(object: any): StakeAuthorization_Validators {
const message = { ...baseStakeAuthorization_Validators } as StakeAuthorization_Validators;
message.address = (object.address ?? []).map((e: any) => String(e));
return message;
},

toJSON(message: StakeAuthorization_Validators): unknown {
const obj: any = {};
if (message.address) {
obj.address = message.address.map((e) => e);
} else {
obj.address = [];
}
return obj;
},

fromPartial<I extends Exact<DeepPartial<StakeAuthorization_Validators>, I>>(
object: I,
): StakeAuthorization_Validators {
const message = { ...baseStakeAuthorization_Validators } as StakeAuthorization_Validators;
message.address = object.address?.map((e) => e) || [];
return message;
},
};

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>
? ReadonlyArray<DeepPartial<U>>
: T extends {}
? { [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();
}