-
Notifications
You must be signed in to change notification settings - Fork 22
/
MsgDelegate.ts
128 lines (117 loc) 路 3.54 KB
/
MsgDelegate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { Coin } from '../../Coin';
import { JSONSerializable } from '../../../util/json';
import { AccAddress, ValAddress } from '../../bech32';
// import { Any } from '@terra-money/legacy.proto/google/protobuf/any';
// import { MsgDelegate as MsgDelegate_pb } from '@terra-money/legacy.proto/cosmos/staking/v1beta1/tx';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgDelegate as MsgDelegate_pb } from '@terra-money/terra.proto/cosmos/staking/v1beta1/tx';
/**
* A delegator can submit this message to send more Luna to be staked through a
* validator delegate.
*/
export class MsgDelegate extends JSONSerializable<
MsgDelegate.Amino,
MsgDelegate.Data,
MsgDelegate.Proto
> {
/**
*
* @param delegator_address delegator's account address
* @param validator_address validator's operator address
* @param amount amount of LUNA to be sent for delegation
*/
constructor(
public delegator_address: AccAddress,
public validator_address: ValAddress,
public amount: Coin
) {
super();
}
public static fromAmino(data: MsgDelegate.Amino, _?: boolean): MsgDelegate {
_;
const {
value: { delegator_address, validator_address, amount },
} = data;
return new MsgDelegate(
delegator_address,
validator_address,
Coin.fromAmino(amount)
);
}
public toAmino(isClassic?: boolean): MsgDelegate.Amino {
const { delegator_address, validator_address, amount } = this;
return {
type: isClassic ? 'staking/MsgDelegate' : 'cosmos-sdk/MsgDelegate',
value: {
delegator_address,
validator_address,
amount: amount.toAmino(),
},
};
}
public static fromProto(proto: MsgDelegate.Proto, _?: boolean): MsgDelegate {
_;
return new MsgDelegate(
proto.delegatorAddress,
proto.validatorAddress,
Coin.fromProto(proto.amount as Coin.Proto)
);
}
public toProto(_?: boolean): MsgDelegate.Proto {
_;
const { delegator_address, validator_address, amount } = this;
return MsgDelegate_pb.fromPartial({
amount: amount.toProto(),
delegatorAddress: delegator_address,
validatorAddress: validator_address,
});
}
public packAny(isClassic?: boolean): Any {
return Any.fromPartial({
typeUrl: '/cosmos.staking.v1beta1.MsgDelegate',
value: MsgDelegate_pb.encode(this.toProto(isClassic)).finish(),
});
}
public static unpackAny(msgAny: Any, isClassic?: boolean): MsgDelegate {
return MsgDelegate.fromProto(
MsgDelegate_pb.decode(msgAny.value),
isClassic
);
}
public static fromData(data: MsgDelegate.Data, _?: boolean): MsgDelegate {
_;
const { delegator_address, validator_address, amount } = data;
return new MsgDelegate(
delegator_address,
validator_address,
Coin.fromData(amount)
);
}
public toData(_?: boolean): MsgDelegate.Data {
_;
const { delegator_address, validator_address, amount } = this;
return {
'@type': '/cosmos.staking.v1beta1.MsgDelegate',
delegator_address,
validator_address,
amount: amount.toData(),
};
}
}
export namespace MsgDelegate {
export interface Amino {
type: 'staking/MsgDelegate' | 'cosmos-sdk/MsgDelegate';
value: {
delegator_address: AccAddress;
validator_address: ValAddress;
amount: Coin.Amino;
};
}
export interface Data {
'@type': '/cosmos.staking.v1beta1.MsgDelegate';
delegator_address: AccAddress;
validator_address: ValAddress;
amount: Coin.Data;
}
export type Proto = MsgDelegate_pb;
}