Skip to content

Commit

Permalink
Add MsgCancelUnbondingDelegation
Browse files Browse the repository at this point in the history
  • Loading branch information
joon9823 committed May 17, 2024
1 parent 834bee1 commit dd39969
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@initia/initia.js",
"version": "0.2.0",
"version": "0.2.1",
"description": "The JavaScript SDK for Initia",
"license": "MIT",
"author": "InitiaLabs",
Expand Down
7 changes: 7 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ import {
MsgDelegate,
MsgEditValidator,
MsgUndelegate,
MsgCancelUnbondingDelegation,
MsgUpdateMstakingParams,
} from './mstaking';
import {
Expand Down Expand Up @@ -559,6 +560,8 @@ export namespace Msg {
return MsgCreateValidator.fromAmino(data);
case 'mstaking/MsgEditValidator':
return MsgEditValidator.fromAmino(data);
case 'mstaking/MsgCancelUnbondingDelegation':
return MsgCancelUnbondingDelegation.fromAmino(data);
case 'mstaking/MsgUpdateParams':
return MsgUpdateMstakingParams.fromAmino(data);

Expand Down Expand Up @@ -957,6 +960,8 @@ export namespace Msg {
return MsgCreateValidator.fromData(data);
case '/initia.mstaking.v1.MsgEditValidator':
return MsgEditValidator.fromData(data);
case '/initia.mstaking.v1.MsgCancelUnbondingDelegation':
return MsgCancelUnbondingDelegation.fromData(data);
case '/initia.mstaking.v1.MsgUpdateParams':
return MsgUpdateMstakingParams.fromData(data);

Expand Down Expand Up @@ -1358,6 +1363,8 @@ export namespace Msg {
return MsgCreateValidator.unpackAny(proto);
case '/initia.mstaking.v1.MsgEditValidator':
return MsgEditValidator.unpackAny(proto);
case '/initia.mstaking.v1.MsgCancelUnbondingDelegation':
return MsgCancelUnbondingDelegation.unpackAny(proto);
case '/initia.mstaking.v1.MsgUpdateParams':
return MsgUpdateMstakingParams.unpackAny(proto);

Expand Down
139 changes: 139 additions & 0 deletions src/core/mstaking/msgs/MsgCancelUnbondingDelegation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { Coins } from '../../Coins';
import { JSONSerializable } from '../../../util/json';
import { AccAddress, ValAddress } from '../../bech32';
import { Any } from '@initia/initia.proto/google/protobuf/any';
import { MsgCancelUnbondingDelegation as MsgCancelUnbondingDelegation_pb } from '@initia/initia.proto/initia/mstaking/v1/tx';
import Long from 'long';

export class MsgCancelUnbondingDelegation extends JSONSerializable<
MsgCancelUnbondingDelegation.Amino,
MsgCancelUnbondingDelegation.Data,
MsgCancelUnbondingDelegation.Proto
> {
public amount: Coins;

/**
* @param delegator_address delegator's account address
* @param validator_address validator's operator address
* @param amount INIT to be undelegated
*/
constructor(
public delegator_address: AccAddress,
public validator_address: ValAddress,
amount: Coins.Input,
public creation_height: number
) {
super();
this.amount = new Coins(amount);
}

public static fromAmino(
data: MsgCancelUnbondingDelegation.Amino
): MsgCancelUnbondingDelegation {
const {
value: { delegator_address, validator_address, amount, creation_height },
} = data;
return new MsgCancelUnbondingDelegation(
delegator_address,
validator_address,
Coins.fromAmino(amount),
Number.parseInt(creation_height)
);
}

public toAmino(): MsgCancelUnbondingDelegation.Amino {
const { delegator_address, validator_address, amount, creation_height } =
this;
return {
type: 'mstaking/MsgCancelUnbondingDelegation',
value: {
delegator_address,
validator_address,
amount: amount.toAmino(),
creation_height: creation_height.toString(),
},
};
}

public static fromData(
data: MsgCancelUnbondingDelegation.Data
): MsgCancelUnbondingDelegation {
const { delegator_address, validator_address, amount, creation_height } =
data;
return new MsgCancelUnbondingDelegation(
delegator_address,
validator_address,
Coins.fromData(amount),
Number.parseInt(creation_height)
);
}

public toData(): MsgCancelUnbondingDelegation.Data {
const { delegator_address, validator_address, amount, creation_height } =
this;
return {
'@type': '/initia.mstaking.v1.MsgCancelUnbondingDelegation',
delegator_address,
validator_address,
amount: amount.toData(),
creation_height: creation_height.toString(),
};
}

public static fromProto(
proto: MsgCancelUnbondingDelegation.Proto
): MsgCancelUnbondingDelegation {
return new MsgCancelUnbondingDelegation(
proto.delegatorAddress,
proto.validatorAddress,
Coins.fromProto(proto.amount as Coins.Proto),
proto.creationHeight.toNumber()
);
}

public toProto(): MsgCancelUnbondingDelegation.Proto {
const { delegator_address, validator_address, amount, creation_height } =
this;
return MsgCancelUnbondingDelegation_pb.fromPartial({
amount: amount.toProto(),
delegatorAddress: delegator_address,
validatorAddress: validator_address,
creationHeight: Long.fromNumber(creation_height),
});
}

public packAny(): Any {
return Any.fromPartial({
typeUrl: '/initia.mstaking.v1.MsgCancelUnbondingDelegation',
value: MsgCancelUnbondingDelegation_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any): MsgCancelUnbondingDelegation {
return MsgCancelUnbondingDelegation.fromProto(
MsgCancelUnbondingDelegation_pb.decode(msgAny.value)
);
}
}

export namespace MsgCancelUnbondingDelegation {
export interface Amino {
type: 'mstaking/MsgCancelUnbondingDelegation';
value: {
delegator_address: AccAddress;
validator_address: ValAddress;
amount: Coins.Amino;
creation_height: string;
};
}

export interface Data {
'@type': '/initia.mstaking.v1.MsgCancelUnbondingDelegation';
delegator_address: AccAddress;
validator_address: ValAddress;
amount: Coins.Data;
creation_height: string;
}

export type Proto = MsgCancelUnbondingDelegation_pb;
}
6 changes: 6 additions & 0 deletions src/core/mstaking/msgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { MsgUndelegate } from './MsgUndelegate';
import { MsgBeginRedelegate } from './MsgBeginRedelegate';
import { MsgCreateValidator } from './MsgCreateValidator';
import { MsgEditValidator } from './MsgEditValidator';
import { MsgCancelUnbondingDelegation } from './MsgCancelUnbondingDelegation';
import { MsgUpdateMstakingParams } from './MsgUpdateMstakingParams';

export * from './MsgDelegate';
export * from './MsgUndelegate';
export * from './MsgBeginRedelegate';
export * from './MsgCreateValidator';
export * from './MsgEditValidator';
export * from './MsgCancelUnbondingDelegation';
export * from './MsgUpdateMstakingParams';

export type MstakingMsg =
Expand All @@ -18,6 +20,7 @@ export type MstakingMsg =
| MsgBeginRedelegate
| MsgCreateValidator
| MsgEditValidator
| MsgCancelUnbondingDelegation
| MsgUpdateMstakingParams;

export namespace MstakingMsg {
Expand All @@ -27,19 +30,22 @@ export namespace MstakingMsg {
| MsgBeginRedelegate.Amino
| MsgCreateValidator.Amino
| MsgEditValidator.Amino
| MsgCancelUnbondingDelegation.Amino
| MsgUpdateMstakingParams.Amino;
export type Data =
| MsgDelegate.Data
| MsgUndelegate.Data
| MsgBeginRedelegate.Data
| MsgCreateValidator.Data
| MsgEditValidator.Data
| MsgCancelUnbondingDelegation.Data
| MsgUpdateMstakingParams.Data;
export type Proto =
| MsgDelegate.Proto
| MsgUndelegate.Proto
| MsgBeginRedelegate.Proto
| MsgCreateValidator.Proto
| MsgEditValidator.Proto
| MsgCancelUnbondingDelegation.Proto
| MsgUpdateMstakingParams.Proto;
}

0 comments on commit dd39969

Please sign in to comment.