Skip to content

Commit aa1947b

Browse files
authored
fix: update amino decode for transfer (#286)
1 parent cf80646 commit aa1947b

File tree

9 files changed

+15
-12
lines changed

9 files changed

+15
-12
lines changed

__tests__/decoder.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as amino from "../src/amino"
2-
import { AminoPrefix } from "../src/types/"
2+
import { unMarshalBinaryLengthPrefixed } from "../src/amino"
3+
import { AminoPrefix, StdTx, SendMsg } from "../src/types/"
34

45
class Msg {
56
constructor(opts) {

__tests__/fixtures/cancelOrder.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"signMsg": {
99
"account_number": "34",
10-
"chain_id": "Binance-Chain-Nile",
10+
"chain_id": "Binance-Chain-Ganges",
1111
"data": null,
1212
"memo": "",
1313
"msgs": [

__tests__/fixtures/placeOrder.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"signMsg": {
1111
"account_number": "34",
12-
"chain_id": "Binance-Chain-Nile",
12+
"chain_id": "Binance-Chain-Ganges",
1313
"data": null,
1414
"memo": "",
1515
"msgs": [

__tests__/fixtures/transfer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"signMsg": {
1010
"account_number": "34",
11-
"chain_id": "Binance-Chain-Nile",
11+
"chain_id": "Binance-Chain-Ganges",
1212
"data": null,
1313
"memo": "test",
1414
"msgs": [

__tests__/rpc.test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as rpcClient from "../src/rpc"
1+
import rpcClient from "../src/rpc"
22

33
const NETWORK = "testnet"
44
const getClient = (type) => {
@@ -22,14 +22,14 @@ describe("rpc", () => {
2222
const client = getClient("https")
2323
const res = await client.status()
2424
expect(res).toBeTruthy()
25-
expect(res.node_info.network).toBe("Binance-Chain-Nile")
25+
expect(res.node_info.network).toBe("Binance-Chain-Ganges")
2626
})
2727

2828
it("wss status", async () => {
2929
const client = getClient("wss")
3030
const res = await client.status()
3131
expect(res).toBeTruthy()
32-
expect(res.node_info.network).toBe("Binance-Chain-Nile")
32+
expect(res.node_info.network).toBe("Binance-Chain-Ganges")
3333
client.close()
3434
})
3535

@@ -210,8 +210,9 @@ describe("rpc", () => {
210210
it("getTxByHash", async () => {
211211
const client = getClient("https")
212212
const hashStr =
213-
"2029ED36444DFE12E6A235CFE8B1C81B7F31014D23790E382056B395EC1171FE"
213+
"5E0C54841CF0261EE111EB6B024762DB200F3FA59397967AB4BC641154C0B789"
214214
const result = await client.getTxByHash(hashStr, true)
215+
// console.log(JSON.stringify(result))
215216
expect(result).toBeTruthy()
216217
expect(result.height).toBeTruthy()
217218
expect(result.hash).toBe(hashStr)

__tests__/transaction.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe("Transaction", () => {
132132
]
133133
const sendMsg = new SendMsg(address, outputs)
134134
const data: StdSignMsg = {
135-
chainId: "Binance-Chain-Nile",
135+
chainId: "Binance-Chain-Ganges",
136136
accountNumber: accountNumber,
137137
sequence: sequence,
138138
baseMsg: sendMsg,

src/amino/decoder/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const decodeArrayBinary = (bytes: Buffer, type: any) => {
193193
const { offset, val } = decodeBinary(bytes, type, true)
194194

195195
arr.push({ ...val })
196-
bytes = bytes.slice(offset)
196+
bytes = bytes.slice(offset + 1)
197197

198198
//add 1 byte of type
199199
arrayOffset += offset + 1

src/rpc/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ class RpcClient extends BaseRpc {
261261
hash,
262262
prove,
263263
})
264-
265264
const txBytes = Buffer.from(res.tx, "base64")
266265
const msgAminoPrefix = txBytes.slice(8, 12).toString("hex")
267266
const msgType = getMsgByAminoPrefix(msgAminoPrefix)

src/types/msg/send.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ export class SendMsg extends BaseMsg {
9494
static defaultMsg() {
9595
return {
9696
inputs: [{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }],
97-
outpus: [{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }],
97+
outputs: [
98+
{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] },
99+
],
98100
aminoPrefix: AminoPrefix.MsgSend,
99101
}
100102
}

0 commit comments

Comments
 (0)