Skip to content

fix: update amino decode for transfer #286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __tests__/decoder.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as amino from "../src/amino"
import { AminoPrefix } from "../src/types/"
import { unMarshalBinaryLengthPrefixed } from "../src/amino"
import { AminoPrefix, StdTx, SendMsg } from "../src/types/"

class Msg {
constructor(opts) {
2 changes: 1 addition & 1 deletion __tests__/fixtures/cancelOrder.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
},
"signMsg": {
"account_number": "34",
"chain_id": "Binance-Chain-Nile",
"chain_id": "Binance-Chain-Ganges",
"data": null,
"memo": "",
"msgs": [
2 changes: 1 addition & 1 deletion __tests__/fixtures/placeOrder.json
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
},
"signMsg": {
"account_number": "34",
"chain_id": "Binance-Chain-Nile",
"chain_id": "Binance-Chain-Ganges",
"data": null,
"memo": "",
"msgs": [
2 changes: 1 addition & 1 deletion __tests__/fixtures/transfer.json
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
},
"signMsg": {
"account_number": "34",
"chain_id": "Binance-Chain-Nile",
"chain_id": "Binance-Chain-Ganges",
"data": null,
"memo": "test",
"msgs": [
9 changes: 5 additions & 4 deletions __tests__/rpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as rpcClient from "../src/rpc"
import rpcClient from "../src/rpc"

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

it("wss status", async () => {
const client = getClient("wss")
const res = await client.status()
expect(res).toBeTruthy()
expect(res.node_info.network).toBe("Binance-Chain-Nile")
expect(res.node_info.network).toBe("Binance-Chain-Ganges")
client.close()
})

@@ -210,8 +210,9 @@ describe("rpc", () => {
it("getTxByHash", async () => {
const client = getClient("https")
const hashStr =
"2029ED36444DFE12E6A235CFE8B1C81B7F31014D23790E382056B395EC1171FE"
"5E0C54841CF0261EE111EB6B024762DB200F3FA59397967AB4BC641154C0B789"
const result = await client.getTxByHash(hashStr, true)
// console.log(JSON.stringify(result))
expect(result).toBeTruthy()
expect(result.height).toBeTruthy()
expect(result.hash).toBe(hashStr)
2 changes: 1 addition & 1 deletion __tests__/transaction.test.ts
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ describe("Transaction", () => {
]
const sendMsg = new SendMsg(address, outputs)
const data: StdSignMsg = {
chainId: "Binance-Chain-Nile",
chainId: "Binance-Chain-Ganges",
accountNumber: accountNumber,
sequence: sequence,
baseMsg: sendMsg,
2 changes: 1 addition & 1 deletion src/amino/decoder/index.ts
Original file line number Diff line number Diff line change
@@ -193,7 +193,7 @@ const decodeArrayBinary = (bytes: Buffer, type: any) => {
const { offset, val } = decodeBinary(bytes, type, true)

arr.push({ ...val })
bytes = bytes.slice(offset)
bytes = bytes.slice(offset + 1)

//add 1 byte of type
arrayOffset += offset + 1
1 change: 0 additions & 1 deletion src/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -261,7 +261,6 @@ class RpcClient extends BaseRpc {
hash,
prove,
})

const txBytes = Buffer.from(res.tx, "base64")
const msgAminoPrefix = txBytes.slice(8, 12).toString("hex")
const msgType = getMsgByAminoPrefix(msgAminoPrefix)
4 changes: 3 additions & 1 deletion src/types/msg/send.ts
Original file line number Diff line number Diff line change
@@ -94,7 +94,9 @@ export class SendMsg extends BaseMsg {
static defaultMsg() {
return {
inputs: [{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }],
outpus: [{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] }],
outputs: [
{ address: Buffer.from(""), coins: [{ denom: "", amount: 0 }] },
],
aminoPrefix: AminoPrefix.MsgSend,
}
}