-
Notifications
You must be signed in to change notification settings - Fork 22
/
SudoContractProposal.ts
152 lines (141 loc) 路 4.08 KB
/
SudoContractProposal.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import { JSONSerializable, removeNull } from '../../../util/json';
import { AccAddress } from '../../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { SudoContractProposal as SudoContractProposal_pb } from '@terra-money/terra.proto/cosmwasm/wasm/v1/proposal';
export class SudoContractProposal extends JSONSerializable<
SudoContractProposal.Amino,
SudoContractProposal.Data,
SudoContractProposal.Proto
> {
/**
* @param title a short summary
* @param description a human readable text
* @param contract contract address to be migrated from
* @param msg JSON message to configure the migrate state of the contract
*/
constructor(
public title: string,
public description: string,
public contract: AccAddress,
public msg: object | string // json object or string
) {
super();
}
public static fromAmino(
data: SudoContractProposal.Amino,
isClassic?: boolean
): SudoContractProposal {
if (isClassic) {
throw new Error('Not supported for the network');
}
const {
value: { title, description, contract, msg },
} = data as SudoContractProposal.Amino;
return new SudoContractProposal(title, description, contract, msg);
}
public toAmino(isClassic?: boolean): SudoContractProposal.Amino {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { title, description, contract, msg } = this;
return {
type: 'wasm/SudoContractProposal',
value: {
title,
description,
contract,
msg: removeNull(msg),
},
};
}
public static fromProto(
proto: SudoContractProposal.Proto,
isClassic?: boolean
): SudoContractProposal {
if (isClassic) {
throw new Error('Not supported for the network');
}
return new SudoContractProposal(
proto.title,
proto.description,
proto.contract,
JSON.parse(Buffer.from(proto.msg).toString('utf-8'))
);
}
public toProto(isClassic?: boolean): SudoContractProposal.Proto {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { title, description, contract, msg } = this;
return SudoContractProposal_pb.fromPartial({
title,
description,
contract,
msg: Buffer.from(JSON.stringify(msg), 'utf-8'),
});
}
public packAny(isClassic?: boolean): Any {
if (isClassic) {
throw new Error('Not supported for the network');
}
return Any.fromPartial({
typeUrl: '/cosmwasm.wasm.v1.SudoContractProposal',
value: SudoContractProposal_pb.encode(this.toProto(isClassic)).finish(),
});
}
public static unpackAny(
msgAny: Any,
isClassic?: boolean
): SudoContractProposal {
if (isClassic) {
throw new Error('Not supported for the network');
}
return SudoContractProposal.fromProto(
SudoContractProposal_pb.decode(msgAny.value),
isClassic
);
}
public static fromData(
data: SudoContractProposal.Data,
isClassic?: boolean
): SudoContractProposal {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { title, description, contract, msg } =
data as SudoContractProposal.Data;
return new SudoContractProposal(title, description, contract, msg);
}
public toData(isClassic?: boolean): SudoContractProposal.Data {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { title, description, contract, msg } = this;
return {
'@type': '/cosmwasm.wasm.v1.SudoContractProposal',
title,
description,
contract,
msg: removeNull(msg),
};
}
}
export namespace SudoContractProposal {
export interface Amino {
type: 'wasm/SudoContractProposal';
value: {
title: string;
description: string;
contract: AccAddress;
msg: object | string;
};
}
export interface Data {
'@type': '/cosmwasm.wasm.v1.SudoContractProposal';
title: string;
description: string;
contract: AccAddress;
msg: object | string;
}
export type Proto = SudoContractProposal_pb;
}