Skip to content

Commit b4f2ac8

Browse files
committed
Add gov msg vote v1
1 parent a5e6271 commit b4f2ac8

File tree

7 files changed

+43
-14
lines changed

7 files changed

+43
-14
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ module.exports = {
1414
},
1515
},
1616
testTimeout: 240000,
17+
moduleNameMapper: {
18+
'@ledgerhq/devices/hid-framing': '@ledgerhq/devices/lib/hid-framing',
19+
},
1720
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
"@cosmjs/stargate": "0.30.1",
5050
"@cosmjs/tendermint-rpc": "0.30.1",
5151
"@cosmjs/utils": "0.30.1",
52-
"@ledgerhq/hw-app-cosmos": "^6.27.10",
53-
"@ledgerhq/hw-transport": "^6.27.10",
52+
"@ledgerhq/hw-app-cosmos": "^6.28.1",
53+
"@ledgerhq/hw-transport": "^6.28.4",
5454
"@types/crypto-js": "^4.1.1",
5555
"@types/ledgerhq__hw-transport": "^4.21.4",
5656
"@types/uuid": "^9.0.0",
5757
"crypto-browserify": "^3.12.0",
5858
"crypto-js": "^4.1.1",
59-
"long": "^5.2.3",
59+
"long": "^4.0.0",
6060
"uuid": "^9.0.0"
6161
},
6262
"optionalDependencies": {},

src/registry/aminoTypes.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { assertDefinedAndNotNull } from '@cosmjs/utils';
1111
import { AminoMsg, Coin } from '@cosmjs/amino';
1212
import Long from 'long';
1313

14+
import { MsgVote } from '../codec/cosmos/gov/v1/tx';
1415
import { MsgDeposit as MsgDepositDfract } from '../codec/lum-network/dfract/tx';
1516
import {
1617
MsgDeposit as MsgMillionsDeposit,
@@ -19,6 +20,17 @@ import {
1920
MsgWithdrawDepositRetry as MsgMillionsWithdrawDepositRetry,
2021
MsgClaimPrize as MsgMillionsClaimPrize,
2122
} from '../codec/lum-network/millions/tx';
23+
24+
export interface AminoMsgGovVote extends AminoMsg {
25+
readonly type: 'cosmos-sdk/v1/MsgVote';
26+
readonly value: {
27+
readonly proposal_id: string;
28+
readonly voter: string;
29+
readonly option: number;
30+
readonly metadata?: string;
31+
};
32+
}
33+
2234
export interface AminoMsgDepositDfract extends AminoMsg {
2335
readonly type: 'lum-network/MsgDeposit';
2436
readonly value: {
@@ -82,11 +94,30 @@ export const createDefaultAminoTypes = (): AminoConverters => {
8294
...createAuthzAminoConverters(),
8395
...createDistributionAminoConverters(),
8496
...createGovAminoConverters(),
97+
...createGovV1AminoConverters(),
8598
...createStakingAminoConverters(),
8699
...createIbcAminoConverters(),
87100
};
88101
};
89102

103+
const createGovV1AminoConverters = (): AminoConverters => ({
104+
'/cosmos.gov.v1.MsgVote': {
105+
aminoType: 'cosmos-sdk/v1/MsgVote',
106+
toAmino: ({ proposalId, voter, option, metadata }: MsgVote): AminoMsgGovVote['value'] => ({
107+
proposal_id: proposalId.toString(),
108+
voter,
109+
option,
110+
metadata: metadata.length > 0 ? metadata : undefined,
111+
}),
112+
fromAmino: ({ proposal_id, voter, option, metadata }: AminoMsgGovVote['value']): MsgVote => ({
113+
proposalId: Long.fromString(proposal_id),
114+
voter,
115+
option,
116+
metadata: metadata || '',
117+
}),
118+
},
119+
});
120+
90121
const createDfractAminoConverters = (): AminoConverters => ({
91122
'/lum.network.dfract.MsgDeposit': {
92123
aminoType: 'lum-network/MsgDeposit',

src/utils/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function uint64FromProto(input: Long) {
1515

1616
function accountFromBaseAccount(input: BaseAccount): LumTypes.Account {
1717
const { address, pubKey, accountNumber, sequence } = input;
18-
const pubkey = decodePubkey(pubKey);
18+
const pubkey = decodePubkey(pubKey as Any);
1919
return {
2020
address: address,
2121
pubkey: pubkey,

src/utils/commons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export const sortJSON = <T>(jsonObj: T): T => {
1818
return jsonObj;
1919
}
2020

21-
let keys = Object.keys(jsonObj) as Array<keyof T>;
21+
let keys = Object.keys(jsonObj as object) as Array<keyof T>;
2222
keys = keys.sort();
2323
const newObject: Partial<T> = {};
2424
for (let i = 0; i < keys.length; i++) {
25-
newObject[keys[i]] = sortJSON(jsonObj[keys[i]]);
25+
newObject[keys[i]] = sortJSON((jsonObj as T)[keys[i]]);
2626
}
2727
return newObject as T;
2828
};

tests/wallet.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { AccountData, DirectSignResponse, OfflineDirectSigner } from '@cosmjs/proto-signing';
22

33
import { SignDoc } from '../src/codec/cosmos/tx/v1beta1/tx';
4-
import { LumWallet, LumWalletFactory, LumUtils, LumConstants, LumMessages, LumRegistry, LumAminoRegistry } from '../src';
4+
import { LumWallet, LumWalletFactory, LumUtils, LumConstants, LumMessages, LumAminoRegistry } from '../src';
55
import { AminoSignResponse, encodeSecp256k1Signature, OfflineAminoSigner, StdSignDoc } from '@cosmjs/amino';
66
import { SignMode } from '../src/codec/cosmos/tx/signing/v1beta1/signing';
77

yarn.lock

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@
14371437
resolved "https://registry.yarnpkg.com/@ledgerhq/errors/-/errors-6.12.6.tgz#f89c82c91c2930f34bc3e0d86a27ec7b6e6e4f5f"
14381438
integrity sha512-D+r2B09vaRO06wfGoss+rNgwqWSoK0bCtsaJWzlD2hv1zxTtucqVtSztbRFypIqxWTCb3ix5Nh2dWHEJVTp2Xw==
14391439

1440-
"@ledgerhq/hw-app-cosmos@^6.27.10":
1440+
"@ledgerhq/hw-app-cosmos@^6.28.1":
14411441
version "6.28.1"
14421442
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-app-cosmos/-/hw-app-cosmos-6.28.1.tgz#7b0c05d40a35cced4e09967eec9a85c530eb0b3e"
14431443
integrity sha512-xlWrkgyuKtmljAtEH9ww7mS8Wv7ek+Ejy8m+XyG7J0Lb88SuXMfwZzj379v5OsSykFqQ4lrWSbA7kG1la5FMBQ==
@@ -1471,7 +1471,7 @@
14711471
node-hid "^2.1.2"
14721472
usb "^1.7.0"
14731473

1474-
"@ledgerhq/hw-transport@^6.27.10", "@ledgerhq/hw-transport@^6.28.4":
1474+
"@ledgerhq/hw-transport@^6.28.4":
14751475
version "6.28.4"
14761476
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.28.4.tgz#c2fc5bff4fca71ac44f069b775d33d0b1b5d9000"
14771477
integrity sha512-fB2H92YQjidmae2GFCmOGPwkZWk0lvTu0tlLlzfiY0wRheAG+DEgjnqhdU8wmydkPLIj0WUjRgldtnJtg/a2iQ==
@@ -4094,11 +4094,6 @@ long@^4.0.0:
40944094
resolved "https://registry.yarnpkg.com/long/-/long-4.0.0.tgz#9a7b71cfb7d361a194ea555241c92f7468d5bf28"
40954095
integrity sha512-XsP+KhQif4bjX1kbuSiySJFNAehNxgLb6hPRGJ9QsUr8ajHkuXGdrHmFUTUUXhDwVX2R5bY4JNZEwbUiMhV+MA==
40964096

4097-
long@^5.2.3:
4098-
version "5.2.3"
4099-
resolved "https://registry.yarnpkg.com/long/-/long-5.2.3.tgz#a3ba97f3877cf1d778eccbcb048525ebb77499e1"
4100-
integrity sha512-lcHwpNoggQTObv5apGNCTdJrO69eHOZMi4BNC+rTLER8iHAqGrUVeLh/irVIM7zTw2bOXA8T6uNPeujwOLg/2Q==
4101-
41024097
lru-cache@^5.1.1:
41034098
version "5.1.1"
41044099
resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920"

0 commit comments

Comments
 (0)