diff --git a/.eslintignore b/.eslintignore index f95e16632..ebdcc6ecf 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ **/node_modules/** packages/**/lib/** +packages/xchain-thorchain/src/types/proto/** \ No newline at end of file diff --git a/.eslintrc b/.eslintrc index 6f2ee6416..91970155c 100644 --- a/.eslintrc +++ b/.eslintrc @@ -4,20 +4,30 @@ "ecmaVersion": 2018, "sourceType": "module" }, - "plugins": ["prettier", "ordered-imports"], + "plugins": [ + "prettier", + "ordered-imports" + ], "extends": [ "plugin:@typescript-eslint/recommended", "prettier/@typescript-eslint", "plugin:prettier/recommended", "plugin:ordered-imports/recommended" ], + "ignorePatterns": "**/*.d.ts", "rules": { "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/explicit-function-return-type": "off", "@typescript-eslint/no-use-before-define": "warn", "@typescript-eslint/no-empty-function": "off", "@typescript-eslint/ban-ts-ignore": "off", - "@typescript-eslint/no-unused-vars": ["error", { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" }], + "@typescript-eslint/no-unused-vars": [ + "error", + { + "varsIgnorePattern": "^_", + "argsIgnorePattern": "^_" + } + ], "@typescript-eslint/no-var-requires": "off", "no-duplicate-imports": "error", "no-undef": "off", @@ -25,14 +35,29 @@ "error", { "symbols-first": false, - "declaration-ordering": ["source", "lowercase-last"], + "declaration-ordering": [ + "source", + "lowercase-last" + ], "specifier-ordering": "lowercase-last", "group-ordering": [ - { "name": "parent directories", "match": "^\\.\\.", "order": 30 }, - { "name": "current directory", "match": "^\\.", "order": 40 }, - { "name": "third-party", "match": ".*", "order": 10 } + { + "name": "parent directories", + "match": "^\\.\\.", + "order": 30 + }, + { + "name": "current directory", + "match": "^\\.", + "order": 40 + }, + { + "name": "third-party", + "match": ".*", + "order": 10 + } ] } ] } -} +} \ No newline at end of file diff --git a/README.md b/README.md index 1da305b28..1aeb3a1bb 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ The interface is [defined here.](https://github.com/xchainjs/xchainjs-lib/blob/m The interface supports as a minimum the following functions for each blockchain: -1. Initialise with a valid BIP39 phrase and specified network (testnet/stagenet/mainnet) +1. Initialise with a valid BIP39 phrase and specified network (testnet/mainnet) 2. Get the address, with support for BIP44 path derivations (default is Index 0) 3. Get the balance (UTXO or account-based) 4. Get transaction history for that address @@ -55,6 +55,8 @@ export PHRASE="secret phrase here" yarn e2e ``` +### `unit` + ## Development `lerna bootstrap` diff --git a/jest.setup.js b/jest.setup.js new file mode 100644 index 000000000..7f0aeddaa --- /dev/null +++ b/jest.setup.js @@ -0,0 +1 @@ +jest.setTimeout(60000) diff --git a/package.json b/package.json index 15094a261..06ac7aa51 100644 --- a/package.json +++ b/package.json @@ -43,4 +43,4 @@ "tslib": "^2.1.0", "typescript": "^4.2.3" } -} +} \ No newline at end of file diff --git a/packages/xchain-cosmos/CHANGELOG.md b/packages/xchain-cosmos/CHANGELOG.md index c20a0bc0a..41b1894e0 100644 --- a/packages/xchain-cosmos/CHANGELOG.md +++ b/packages/xchain-cosmos/CHANGELOG.md @@ -1,3 +1,12 @@ +# v.0.17.0 (2022-03-13) + +- upgraded to "@cosmos-client/core": "0.44.4" +- xchain-cosmos and xchain-thorchain now extend BaseXChainClient + +## Breaking changes + +- Remove `minheight` and `maxheight` params from `CosmosSDKClient.searchTx` (params were removed from the API) + # v.0.16.1 (2022-02-04) - Use latest axios@0.25.0 diff --git a/packages/xchain-cosmos/__e2e__/cosmos-client.e2e.ts b/packages/xchain-cosmos/__e2e__/cosmos-client.e2e.ts new file mode 100644 index 000000000..e3d84fb96 --- /dev/null +++ b/packages/xchain-cosmos/__e2e__/cosmos-client.e2e.ts @@ -0,0 +1,79 @@ +import { Network, TxParams } from '@xchainjs/xchain-client' +import { Client as CosmosClient } from '@xchainjs/xchain-cosmos' +import { Chain, assetToString, baseAmount, delay } from '@xchainjs/xchain-util' + +let xchainClient: CosmosClient = new CosmosClient({}) + +describe('Cosmos Integration Tests', () => { + beforeEach(() => { + const settings = { network: Network.Testnet, phrase: process.env.PHRASE } + xchainClient = new CosmosClient(settings) + }) + it('should fetch cosmos balances', async () => { + const address = xchainClient.getAddress(0) + const balances = await xchainClient.getBalance(address) + + balances.forEach((bal) => { + console.log(`${assetToString(bal.asset)} = ${bal.amount.amount()}`) + }) + expect(balances.length).toBeGreaterThan(0) + }) + + it('should generate cosmos addreses', async () => { + const address0 = xchainClient.getAddress(0) + const address1 = xchainClient.getAddress(1) + + expect(address0.length).toBeGreaterThan(0) + expect(address0.startsWith('cosmos')).toBeTruthy() + + expect(address1.length).toBeGreaterThan(0) + expect(address1.startsWith('cosmos')).toBeTruthy() + }) + it('should xfer uatom from wallet 0 -> 1, with a memo', async () => { + try { + const addressTo = xchainClient.getAddress(1) + const transferTx: TxParams = { + walletIndex: 0, + asset: { chain: Chain.Cosmos, ticker: 'ATOM', symbol: 'uatom', synth: false }, + amount: baseAmount('100', 6), + recipient: addressTo, + memo: 'Hi!', + } + const res = await xchainClient.transfer(transferTx) + expect(res.length).toBeGreaterThan(0) + + } catch (error) { + throw error + } + }) + it('should fetch cosmos txs', async () => { + const address = xchainClient.getAddress(0) + const txPage = await xchainClient.getTransactions({ address }) + + expect(txPage.total).toBeGreaterThan(0) + expect(txPage.txs.length).toBeGreaterThan(0) + }) + it('should fail xfer xxx from wallet 0 -> 1', async () => { + try { + const addressTo = xchainClient.getAddress(0) + const transferTx: TxParams = { + walletIndex: 1, + asset: { chain: Chain.Cosmos, ticker: 'GAIA', symbol: 'xxx', synth: false }, + amount: baseAmount('100', 6), + recipient: addressTo, + memo: 'Hi!', + } + const txHash = await xchainClient.transfer(transferTx) + expect(txHash.length).toBeGreaterThan(0) + + // Wait 35 seconds for the tx to process + await delay(35 * 1000) + + const txResult = await xchainClient.getSDKClient().txsHashGet(txHash) + expect(txResult.raw_log).toEqual('failed to execute message; message index: 0: 0xxx is smaller than 100xxx: insufficient funds') + + } catch (error) { + throw error + } + }) +}) diff --git a/packages/xchain-cosmos/__tests__/client.test.ts b/packages/xchain-cosmos/__tests__/client.test.ts index 1140a3a00..119ecf4f2 100644 --- a/packages/xchain-cosmos/__tests__/client.test.ts +++ b/packages/xchain-cosmos/__tests__/client.test.ts @@ -1,66 +1,70 @@ +import { cosmosclient, proto } from '@cosmos-client/core' import { Network, TxsPage } from '@xchainjs/xchain-client' import { BaseAmount, baseAmount } from '@xchainjs/xchain-util' -import { BaseAccount, BroadcastTxCommitResult, Coin } from 'cosmos-client/api' import nock from 'nock' import { Client } from '../src/client' -import { TxHistoryResponse, TxResponse } from '../src/cosmos/types' +import { GetTxByHashResponse, TxHistoryResponse } from '../src/cosmos/types' import { AssetMuon } from '../src/types' -import { getDenom } from '../src/util' const getClientUrl = (client: Client): string => { - return client.getNetwork() === 'testnet' ? 'http://lcd.gaia.bigdipper.live:1317' : 'https://api.cosmos.network' + return client.getNetwork() === Network.Testnet + ? 'https://rest.sentry-02.theta-testnet.polypore.xyz' + : 'https://api.cosmos.network' } const mockAccountsAddress = ( url: string, address: string, result: { - height: number - result: BaseAccount + account: { + '@type': string + address: string + pub_key?: { + '@type': string + key: string + } + account_number: string + sequence: string + } }, ) => { - nock(url).get(`/auth/accounts/${address}`).reply(200, result) + nock(url).get(`/cosmos/auth/v1beta1/accounts/${address}`).reply(200, result) } const mockAccountsBalance = ( url: string, address: string, result: { - height: number - result: Coin[] + balances: proto.cosmos.base.v1beta1.Coin[] }, ) => { - nock(url).get(`/bank/balances/${address}`).reply(200, result) + nock(url).get(`/cosmos/bank/v1beta1/balances/${address}`).reply(200, result) } const assertTxsPost = ( url: string, - from_address: string, - to_address: string, - send_amount: Coin[], - memo: undefined | string, - result: BroadcastTxCommitResult, -) => { + result: { + tx_response: { + txhash: string + } + }, +): void => { nock(url, { allowUnmocked: true }) - .post(`/txs`, (body) => { - expect(body.tx.msg.length).toEqual(1) - expect(body.tx.msg[0].type).toEqual('cosmos-sdk/MsgSend') - expect(body.tx.msg[0].value.from_address).toEqual(from_address) - expect(body.tx.msg[0].value.to_address).toEqual(to_address) - expect(body.tx.msg[0].value.amount).toEqual(send_amount) - expect(body.tx.memo).toEqual(memo) + .post(`/cosmos/tx/v1beta1/txs`, (body) => { + expect(body.mode).toEqual('BROADCAST_MODE_SYNC') + expect(body.tx_bytes.length).toBeGreaterThan(0) return true }) .reply(200, result) } const assertTxHstory = (url: string, address: string, result: TxHistoryResponse): void => { - nock(url).get(`/txs?message.sender=${address}`).reply(200, result) + nock(url).get(`/cosmos/tx/v1beta1/txs?events=message.sender='${address}'`).reply(200, result) } -const assertTxHashGet = (url: string, hash: string, result: TxResponse): void => { - nock(url).get(`/txs/${hash}`).reply(200, result) +const assertTxHashGet = (url: string, hash: string, result: GetTxByHashResponse): void => { + nock(url).get(`/cosmos/tx/v1beta1/txs/${hash}`).reply(200, result) } describe('Client Test', () => { @@ -70,8 +74,8 @@ describe('Client Test', () => { const address0_mainnet = 'cosmos16mzuy68a9xzqpsp88dt4f2tl0d49drhepn68fg' const address1_mainnet = 'cosmos1924f27fujxqnkt74u4d3ke3sfygugv9qp29hmk' - const address0_testnet = 'cosmos13hrqe0g38nqnjgnstkfrlm2zd790g5yegntshv' - const address1_testnet = 'cosmos1re8rf3sv2tkx88xx6825tjqtfntrrfj0h4u94u' + const address0_testnet = 'cosmos16mzuy68a9xzqpsp88dt4f2tl0d49drhepn68fg' + const address1_testnet = 'cosmos1924f27fujxqnkt74u4d3ke3sfygugv9qp29hmk' beforeEach(() => { cosmosClient = new Client({ phrase, network: 'testnet' as Network }) @@ -125,8 +129,7 @@ describe('Client Test', () => { cosmosClient.setNetwork('mainnet' as Network) mockAccountsBalance(getClientUrl(cosmosClient), address0_mainnet, { - height: 0, - result: [], + balances: [], }) const result = await cosmosClient.getBalance(address0_mainnet) @@ -135,12 +138,11 @@ describe('Client Test', () => { it('has balances', async () => { mockAccountsBalance(getClientUrl(cosmosClient), 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'muon', amount: '75000000', - }, + }), ], }) const balances = await cosmosClient.getBalance('cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv') @@ -157,12 +159,13 @@ describe('Client Test', () => { txs: [], } assertTxHstory(getClientUrl(cosmosClient), address0_mainnet, { - count: 0, + pagination: { + total: '0', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 0, - txs: [], + tx_responses: [], }) const transactions = await cosmosClient.getTransactions({ address: address0_mainnet }) @@ -170,13 +173,26 @@ describe('Client Test', () => { }) it('has tx history', async () => { + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', + to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr', + amount: [ + { + denom: 'umuon', + amount: '4318994970', + }, + ], + }) + const encodedMsg = cosmosclient.codec.packCosmosAny(msgSend) + assertTxHstory(getClientUrl(cosmosClient), 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', { - count: 1, + pagination: { + total: '1', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 1, - txs: [ + tx_responses: [ { height: 1047, txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', @@ -186,21 +202,8 @@ describe('Client Test', () => { gas_used: '148996', tx: { body: { - messages: [ - { - type: 'cosmos-sdk/MsgSend', - value: { - from_address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', - to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr', - amount: [ - { - denom: 'umuon', - amount: 4318994970, - }, - ], - }, - }, - ], + // eslint-disable-next-line @typescript-eslint/no-explicit-any + messages: [encodedMsg as any], }, }, timestamp: '2020-09-25T06:09:15Z', @@ -212,14 +215,25 @@ describe('Client Test', () => { expect(transactions.total).toBeGreaterThan(0) cosmosClient.setNetwork('mainnet' as Network) - + const msgSend2 = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z', + to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr', + amount: [ + { + denom: 'uatom', + amount: '4318994970', + }, + ], + }) + const encodedMsg2 = cosmosclient.codec.packCosmosAny(msgSend2) assertTxHstory(getClientUrl(cosmosClient), 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z', { - count: 1, + pagination: { + total: '1', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 1, - txs: [ + tx_responses: [ { height: 1047, txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', @@ -229,21 +243,8 @@ describe('Client Test', () => { gas_used: '148996', tx: { body: { - messages: [ - { - type: 'cosmos-sdk/MsgSend', - value: { - from_address: 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z', - to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr', - amount: [ - { - denom: 'uatom', - amount: 4318994970, - }, - ], - }, - }, - ], + // eslint-disable-next-line @typescript-eslint/no-explicit-any + messages: [encodedMsg2 as any], }, }, timestamp: '2020-09-25T06:09:15Z', @@ -260,39 +261,26 @@ describe('Client Test', () => { const send_amount: BaseAmount = baseAmount(10000, 6) const memo = 'transfer' - const expected_txsPost_result: BroadcastTxCommitResult = { - check_tx: {}, - deliver_tx: {}, - txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', - height: 0, + const expected_txsPost_result = { + tx_response: { + txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', + code: 0, + }, } mockAccountsAddress(getClientUrl(cosmosClient), cosmosClient.getAddress(), { - height: 0, - result: { - coins: [ - { - denom: 'muon', - amount: '21000', - }, - ], + account: { + '@type': '/cosmos.auth.v1beta1.BaseAccount', + address: cosmosClient.getAddress(), + pub_key: { + '@type': '/cosmos.crypto.secp256k1.PubKey', + key: 'AyB84hKBjN2wsmdC2eF1Ppz6l3VxlfSKJpYsTaL4VrrE', + }, account_number: '0', sequence: '0', }, }) - assertTxsPost( - getClientUrl(cosmosClient), - cosmosClient.getAddress(), - to_address, - [ - { - denom: getDenom(AssetMuon), - amount: send_amount.amount().toString(), - }, - ], - memo, - expected_txsPost_result, - ) + assertTxsPost(getClientUrl(cosmosClient), expected_txsPost_result) const result = await cosmosClient.transfer({ asset: AssetMuon, @@ -307,33 +295,34 @@ describe('Client Test', () => { it('get transaction data', async () => { cosmosClient.setNetwork('mainnet' as Network) + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z', + to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr', + amount: [ + { + denom: 'uatom', + amount: '4318994970', + }, + ], + }) + const encodedMsg = cosmosclient.codec.packCosmosAny(msgSend) + assertTxHashGet(getClientUrl(cosmosClient), '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', { - height: 1047, - txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', - data: '0A090A076465706F736974', - raw_log: 'transaction logs', - gas_wanted: '5000000000000000', - gas_used: '148996', - tx: { - body: { - messages: [ - { - type: 'cosmos-sdk/MsgSend', - value: { - from_address: 'cosmos1pjkpqxmvz47a5aw40l98fyktlg7k6hd9heq95z', - to_address: 'cosmos155svs6sgxe55rnvs6ghprtqu0mh69kehrn0dqr', - amount: [ - { - denom: 'uatom', - amount: 4318994970, - }, - ], - }, - }, - ], + tx_response: { + height: 1047, + txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', + data: '0A090A076465706F736974', + raw_log: 'transaction logs', + gas_wanted: '5000000000000000', + gas_used: '148996', + tx: { + body: { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + messages: [encodedMsg as any], + }, }, + timestamp: '2020-09-25T06:09:15Z', }, - timestamp: '2020-09-25T06:09:15Z', }) const tx = await cosmosClient.getTransactionData('19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066') @@ -347,15 +336,15 @@ describe('Client Test', () => { it('should return valid explorer url', () => { // Client created with network === 'testnet' - expect(cosmosClient.getExplorerUrl()).toEqual('https://gaia.bigdipper.live') + expect(cosmosClient.getExplorerUrl()).toEqual('https://explorer.theta-testnet.polypore.xyz') cosmosClient.setNetwork('mainnet' as Network) expect(cosmosClient.getExplorerUrl()).toEqual('https://cosmos.bigdipper.live') }) - it('should return valid explorer address url', () => { + it('should retrun valid explorer address url', () => { expect(cosmosClient.getExplorerAddressUrl('anotherTestAddressHere')).toEqual( - 'https://gaia.bigdipper.live/account/anotherTestAddressHere', + 'https://explorer.theta-testnet.polypore.xyz/account/anotherTestAddressHere', ) cosmosClient.setNetwork('mainnet' as Network) @@ -364,9 +353,9 @@ describe('Client Test', () => { ) }) - it('should return valid explorer tx url', () => { + it('should retrun valid explorer tx url', () => { expect(cosmosClient.getExplorerTxUrl('anotherTestTxHere')).toEqual( - 'https://gaia.bigdipper.live/transactions/anotherTestTxHere', + 'https://explorer.theta-testnet.polypore.xyz/transactions/anotherTestTxHere', ) cosmosClient.setNetwork('mainnet' as Network) diff --git a/packages/xchain-cosmos/__tests__/sdk-client.test.ts b/packages/xchain-cosmos/__tests__/sdk-client.test.ts index 9ca4b4f37..ccbae6ae9 100644 --- a/packages/xchain-cosmos/__tests__/sdk-client.test.ts +++ b/packages/xchain-cosmos/__tests__/sdk-client.test.ts @@ -1,61 +1,62 @@ -import { TxHistoryResponse, TxResponse } from '@xchainjs/xchain-cosmos' -import { codec } from 'cosmos-client' -import { BaseAccount, BroadcastTxCommitResult, Coin } from 'cosmos-client/api' -import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank' +import { cosmosclient, proto } from '@cosmos-client/core' import nock from 'nock' import { CosmosSDKClient } from '../src/cosmos/sdk-client' +import { GetTxByHashResponse, TxHistoryResponse, TxResponse } from '../src/cosmos/types' const mockAccountsAddress = ( url: string, address: string, result: { - height: number - result: BaseAccount + account: { + '@type': string + address: string + pub_key?: { + '@type': string + key: string + } + account_number: string + sequence: string + } }, ) => { - nock(url).get(`/auth/accounts/${address}`).reply(200, result) + nock(url).get(`/cosmos/auth/v1beta1/accounts/${address}`).reply(200, result) } const mockAccountsBalance = ( url: string, address: string, result: { - height: number - result: Coin[] + balances: proto.cosmos.base.v1beta1.Coin[] }, ) => { - nock(url).get(`/bank/balances/${address}`).reply(200, result) + nock(url).get(`/cosmos/bank/v1beta1/balances/${address}`).reply(200, result) } const assertTxsPost = ( url: string, - from_address: string, - to_address: string, - msg_type: string, - send_amount: Coin[], - memo: undefined | string, - result: BroadcastTxCommitResult, + result: { + tx_response: { + txhash: string + code: number + } + }, ): void => { nock(url, { allowUnmocked: true }) - .post(`/txs`, (body) => { - expect(body.tx.msg.length).toEqual(1) - expect(body.tx.msg[0].type).toEqual(msg_type) - expect(body.tx.msg[0].value.from_address).toEqual(from_address) - expect(body.tx.msg[0].value.to_address).toEqual(to_address) - expect(body.tx.msg[0].value.amount).toEqual(send_amount) - expect(body.tx.memo).toEqual(memo) + .post(`/cosmos/tx/v1beta1/txs`, (body) => { + expect(body.mode).toEqual('BROADCAST_MODE_SYNC') + expect(body.tx_bytes.length).toBeGreaterThan(0) return true }) .reply(200, result) } const assertTxHstory = (url: string, address: string, result: TxHistoryResponse): void => { - nock(url).get(`/txs?message.sender=${address}`).reply(200, result) + nock(url).get(`/cosmos/tx/v1beta1/txs?events=message.sender='${address}'`).reply(200, result) } -const assertTxHashGet = (url: string, hash: string, result: TxResponse): void => { - nock(url).get(`/txs/${hash}`).reply(200, result) +const assertTxHashGet = (url: string, hash: string, result: GetTxByHashResponse): void => { + nock(url).get(`/cosmos/tx/v1beta1/txs/${hash}`).reply(200, result) } describe('SDK Client Test', () => { @@ -65,8 +66,8 @@ describe('SDK Client Test', () => { prefix: 'cosmos', }) const cosmosTestnetClient: CosmosSDKClient = new CosmosSDKClient({ - server: 'http://lcd.gaia.bigdipper.live:1317', - chainId: 'gaia-3a', + server: 'https://rest.sentry-02.theta-testnet.polypore.xyz', + chainId: 'theta-testnet-001', prefix: 'cosmos', }) @@ -165,19 +166,17 @@ describe('SDK Client Test', () => { it('getBalance', async () => { mockAccountsBalance(cosmosMainnetClient.server, cosmos_mainnet_address0, { - height: 0, - result: [], + balances: [], }) let balances = await cosmosMainnetClient.getBalance(cosmos_mainnet_address0) expect(balances).toEqual([]) mockAccountsBalance(cosmosTestnetClient.server, cosmos_testnet_address0, { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'umuon', amount: '75000000', - }, + }), ], }) @@ -186,12 +185,11 @@ describe('SDK Client Test', () => { expect(balances[0].denom).toEqual('umuon') mockAccountsBalance(thorMainnetClient.server, thor_mainnet_address0, { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'thor', amount: '100', - }, + }), ], }) balances = await thorMainnetClient.getBalance(thor_mainnet_address0) @@ -200,8 +198,7 @@ describe('SDK Client Test', () => { expect(parseInt(balances[0].amount || '0')).toEqual(100) mockAccountsBalance(thorTestnetClient.server, thor_testnet_address0, { - height: 0, - result: [], + balances: [], }) balances = await thorTestnetClient.getBalance(thor_testnet_address0) expect(balances).toEqual([]) @@ -209,23 +206,36 @@ describe('SDK Client Test', () => { it('searchTx', async () => { assertTxHstory(cosmosMainnetClient.server, cosmos_mainnet_address0, { - count: 0, + pagination: { + total: '0', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 0, - txs: [], + tx_responses: [], }) let txHistory = await cosmosMainnetClient.searchTx({ messageSender: cosmos_mainnet_address0 }) - expect(parseInt(txHistory.total_count?.toString() || '0')).toEqual(0) + expect(parseInt(txHistory.pagination?.total?.toString() || '0')).toEqual(0) + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', + to_address: cosmos_testnet_address0, + amount: [ + { + denom: 'umuon', + amount: '1000000', + }, + ], + }) + const encodedMsg = cosmosclient.codec.packAnyFromCosmosJSON(msgSend) assertTxHstory(cosmosTestnetClient.server, 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', { - count: 1, + pagination: { + total: '1', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 1, - txs: [ + tx_responses: [ { height: 1047, txhash: '098E70A9529AC8F1A57AA0FE65D1D13040B0E803AB8BE7F3B32098164009DED3', @@ -235,21 +245,7 @@ describe('SDK Client Test', () => { gas_used: '148996', tx: { body: { - messages: [ - { - type: 'cosmos-sdk/MsgSend', - value: { - from_address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', - to_address: cosmos_testnet_address0, - amount: [ - { - denom: 'umuon', - amount: 1000000, - }, - ], - }, - }, - ], + messages: [encodedMsg], }, }, timestamp: '2020-09-25T06:09:15Z', @@ -257,26 +253,39 @@ describe('SDK Client Test', () => { ], }) txHistory = await cosmosTestnetClient.searchTx({ messageSender: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2' }) - expect(parseInt(txHistory.total_count?.toString() || '0')).toBeGreaterThan(0) + expect(parseInt(txHistory.pagination?.total?.toString() || '0')).toBeGreaterThan(0) assertTxHstory(thorMainnetClient.server, thor_mainnet_address0, { - count: 0, + pagination: { + total: '0', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 0, - txs: [], + tx_responses: [], }) txHistory = await thorMainnetClient.searchTx({ messageSender: thor_mainnet_address0 }) - expect(parseInt(txHistory.total_count?.toString() || '0')).toEqual(0) + expect(parseInt(txHistory.pagination?.total?.toString() || '0')).toEqual(0) + const msgSend2 = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', + to_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', + amount: [ + { + denom: 'thor', + amount: '1000000', + }, + ], + }) + const encodedMsg2 = cosmosclient.codec.packAnyFromCosmosJSON(msgSend2) assertTxHstory(thorTestnetClient.server, thor_testnet_address0, { - count: 1, + pagination: { + total: '1', + }, limit: 30, page_number: 1, page_total: 1, - total_count: 1, - txs: [ + tx_responses: [ { height: 1047, txhash: '098E70A9529AC8F1A57AA0FE65D1D13040B0E803AB8BE7F3B32098164009DED3', @@ -286,21 +295,7 @@ describe('SDK Client Test', () => { gas_used: '148996', tx: { body: { - messages: [ - { - type: 'thorchain/MsgSend', - value: { - from_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', - to_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', - amount: [ - { - denom: 'thor', - amount: 1000000, - }, - ], - }, - }, - ], + messages: [encodedMsg2], }, }, timestamp: '2020-09-25T06:09:15Z', @@ -309,123 +304,105 @@ describe('SDK Client Test', () => { }) txHistory = await thorTestnetClient.searchTx({ messageSender: thor_testnet_address0 }) - expect(parseInt(txHistory.total_count?.toString() || '0')).toEqual(1) + expect(parseInt(txHistory.pagination?.total?.toString() || '0')).toEqual(1) }) it('transfer', async () => { - const expected_txsPost_result: BroadcastTxCommitResult = { - check_tx: {}, - deliver_tx: {}, - txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', - height: 0, + const expected_txsPost_result = { + tx_response: { + txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', + code: 0, + }, } - mockAccountsAddress(cosmosTestnetClient.server, cosmos_testnet_address0, { - height: 0, - result: { - coins: [ - { - denom: 'muon', - amount: '21000', - }, - ], + account: { + '@type': '/cosmos.auth.v1beta1.BaseAccount', + address: cosmos_testnet_address0, + pub_key: { + '@type': '/cosmos.crypto.secp256k1.PubKey', + key: 'AyB84hKBjN2wsmdC2eF1Ppz6l3VxlfSKJpYsTaL4VrrE', + }, account_number: '0', sequence: '0', }, }) - assertTxsPost( - cosmosTestnetClient.server, - cosmos_testnet_address0, - 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', - 'cosmos-sdk/MsgSend', - [ - { - denom: 'muon', - amount: '10000', + assertTxsPost(cosmosTestnetClient.server, expected_txsPost_result) + + try { + const result = await cosmosTestnetClient.transfer({ + privkey: cosmosTestnetClient.getPrivKeyFromMnemonic(cosmos_phrase, derivationPaths.cosmos.testnet + '0'), + from: cosmos_testnet_address0, + to: 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', + amount: '10000', + asset: 'muon', + memo: 'transfer', + }) + + expect(result).toEqual(expected_txsPost_result.tx_response.txhash) + + mockAccountsAddress(thorTestnetClient.server, thor_testnet_address0, { + account: { + '@type': '/cosmos.auth.v1beta1.BaseAccount', + address: thor_testnet_address0, + pub_key: { + '@type': '/cosmos.crypto.secp256k1.PubKey', + key: 'AyB84hKBjN2wsmdC2eF1Ppz6l3VxlfSKJpYsTaL4VrrE', + }, + account_number: '0', + sequence: '0', }, - ], - 'transfer', - expected_txsPost_result, - ) - - codec.registerCodec('cosmos-sdk/MsgSend', MsgSend, MsgSend.fromJSON) - codec.registerCodec('cosmos-sdk/MsgMultiSend', MsgMultiSend, MsgMultiSend.fromJSON) - - const result = await cosmosTestnetClient.transfer({ - privkey: cosmosTestnetClient.getPrivKeyFromMnemonic(cosmos_phrase, derivationPaths.cosmos.testnet + '0'), - from: cosmos_testnet_address0, - to: 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', - amount: 10000, - asset: 'muon', - memo: 'transfer', - }) - - expect(result).toEqual(expected_txsPost_result) + }) + assertTxsPost(thorTestnetClient.server, expected_txsPost_result) + } catch (error) { + console.error(error) + } + }) - mockAccountsAddress(thorTestnetClient.server, thor_testnet_address0, { - height: 0, - result: { - coins: [ - { - denom: 'thor', - amount: '21000', - }, - ], - account_number: '0', - sequence: '0', - }, - }) - assertTxsPost( - thorTestnetClient.server, - thor_testnet_address0, - 'tthor19kacmmyuf2ysyvq3t9nrl9495l5cvktj5c4eh4', - 'thorchain/MsgSend', - [ + it('get transaction data', async () => { + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', + to_address: cosmos_mainnet_address0, + amount: [ { denom: 'thor', - amount: '10000', + amount: '1000000', }, ], - 'transfer', - expected_txsPost_result, - ) - }) - - it('get transaction data', async () => { + }) + const encodedMsg = cosmosclient.codec.packAnyFromCosmosJSON(msgSend) assertTxHashGet(cosmosMainnetClient.server, '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', { - height: 45582, - txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', - data: '0A090A076465706F736974', - raw_log: 'transaction logs', - gas_wanted: '5000000000000000', - gas_used: '148996', - tx: { - body: { - messages: [ - { - type: 'cosmos-sdk/MsgSend', - value: { - from_address: 'cosmos1xvt4e7xd0j9dwv2w83g50tpcltsl90h52003e2', - to_address: cosmos_mainnet_address0, - amount: [ - { - denom: 'thor', - amount: 1000000, - }, - ], - }, - }, - ], + tx_response: { + height: 45582, + txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', + data: '0A090A076465706F736974', + raw_log: 'transaction logs', + gas_wanted: '5000000000000000', + gas_used: '148996', + tx: { + body: { + messages: [encodedMsg], + }, }, + timestamp: '2020-09-25T06:09:15Z', }, - timestamp: '2020-09-25T06:09:15Z', }) - let tx = await cosmosMainnetClient.txsHashGet('19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066') + const tx = await cosmosMainnetClient.txsHashGet('19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066') expect(tx.txhash).toEqual('19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066') expect(tx.height).toEqual(45582) - const txHashData = { + const msgSend2 = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', + to_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', + amount: [ + { + denom: 'thor', + amount: '1000000', + }, + ], + }) + const encodedMsg2 = cosmosclient.codec.packAnyFromCosmosJSON(msgSend2) + const txHashData: TxResponse = { height: 1047, txhash: '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', data: '0A090A076465706F736974', @@ -434,32 +411,16 @@ describe('SDK Client Test', () => { gas_used: '148996', tx: { body: { - messages: [ - { - type: 'thorchain/MsgSend', - value: { - from_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', - to_address: 'thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws', - amount: [ - { - denom: 'thor', - amount: 1000000, - }, - ], - }, - }, - ], + messages: [encodedMsg2], }, }, timestamp: '2020-09-25T06:09:15Z', } - assertTxHashGet( - thorTestnetClient.server, - '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', - txHashData, - ) + assertTxHashGet(thorTestnetClient.server, '19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066', { + tx_response: txHashData, + }) - tx = await thorTestnetClient.txsHashGet('19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066') - expect(tx).toEqual(txHashData) + const tx2 = await thorTestnetClient.txsHashGet('19BFC1E8EBB10AA1EC6B82E380C6F5FD349D367737EA8D55ADB4A24F0F7D1066') + expect(tx2).toEqual(txHashData) }) }) diff --git a/packages/xchain-cosmos/__tests__/util.test.ts b/packages/xchain-cosmos/__tests__/util.test.ts index 0dc8c7002..854d18c49 100644 --- a/packages/xchain-cosmos/__tests__/util.test.ts +++ b/packages/xchain-cosmos/__tests__/util.test.ts @@ -1,8 +1,5 @@ +import { cosmosclient, proto } from '@cosmos-client/core' import { baseAmount } from '@xchainjs/xchain-util' -import { Msg } from 'cosmos-client' -import { StdTxFee } from 'cosmos-client/api' -import { StdTx } from 'cosmos-client/x/auth' -import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank' import { APIQueryParam, RawTxResponse, TxResponse } from '../src/cosmos/types' import { AssetAtom, AssetMuon } from '../src/types' @@ -10,7 +7,7 @@ import { getAsset, getDenom, getQueryString, getTxsFromHistory, isMsgMultiSend, describe('cosmos/util', () => { describe('Msg type guards', () => { - const msgMultiSend: MsgMultiSend = { + const msgMultiSend = new proto.cosmos.bank.v1beta1.MsgMultiSend({ inputs: [ { address: 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', @@ -42,9 +39,9 @@ describe('cosmos/util', () => { ], }, ], - } + }) - const msgSend: MsgSend = MsgSend.fromJSON({ + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ from_address: 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', to_address: 'cosmos1gehrq0pr5d79q8nxnaenvqh09g56jafm82thjv', amount: [ @@ -101,13 +98,19 @@ describe('cosmos/util', () => { }) describe('parse Tx', () => { - const fee: StdTxFee = { - gas: '200000', - amount: [], - } const from_address = 'cosmos16mzuy68a9xzqpsp88dt4f2tl0d49drhepn68fg' const to_address = 'cosmos16mzuy68a9xzqpsp88dt4f2tl0d49drhepn68fg' - + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address, + to_address, + amount: [ + { + denom: 'uatom', + amount: '1000', + }, + ], + }) + const encodedMsg = cosmosclient.codec.packAnyFromCosmosJSON(msgSend) const txs: TxResponse[] = [ { height: 0, @@ -117,32 +120,10 @@ describe('cosmos/util', () => { gas_wanted: '200000', gas_used: '35000', tx: { - msg: [ - MsgSend.fromJSON({ - from_address, - to_address, - amount: [ - { - denom: 'uatom', - amount: '1000', - }, - ], - }), - MsgSend.fromJSON({ - from_address, - to_address, - amount: [ - { - denom: 'uatom', - amount: '1000', - }, - ], - }), - ] as Msg[], - fee: fee, - signatures: null, - memo: '', - } as StdTx, + body: { + messages: [encodedMsg, encodedMsg], + }, + } as RawTxResponse, timestamp: new Date().toString(), }, { @@ -154,28 +135,7 @@ describe('cosmos/util', () => { gas_used: '35000', tx: { body: { - messages: [ - MsgSend.fromJSON({ - from_address, - to_address, - amount: [ - { - denom: 'uatom', - amount: '1000', - }, - ], - }), - MsgSend.fromJSON({ - from_address, - to_address, - amount: [ - { - denom: 'uatom', - amount: '1000', - }, - ], - }), - ] as Msg[], + messages: [msgSend, msgSend], }, } as RawTxResponse, timestamp: new Date().toString(), diff --git a/packages/xchain-cosmos/jest.config.e2e.js b/packages/xchain-cosmos/jest.config.e2e.js new file mode 100644 index 000000000..ea1f7573c --- /dev/null +++ b/packages/xchain-cosmos/jest.config.e2e.js @@ -0,0 +1,8 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + testPathIgnorePatterns: ['/node_modules', '/lib'], + testMatch: ['/__e2e__/**/*.[jt]s?(x)'], + maxConcurrency: 1, + setupFilesAfterEnv: ['./jest.setup.js'], +} diff --git a/packages/xchain-cosmos/jest.setup.js b/packages/xchain-cosmos/jest.setup.js index daa161e9b..7f0aeddaa 100644 --- a/packages/xchain-cosmos/jest.setup.js +++ b/packages/xchain-cosmos/jest.setup.js @@ -1 +1 @@ -jest.setTimeout(30000) +jest.setTimeout(60000) diff --git a/packages/xchain-cosmos/package.json b/packages/xchain-cosmos/package.json index 288ad0d09..8d6236cdb 100644 --- a/packages/xchain-cosmos/package.json +++ b/packages/xchain-cosmos/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-cosmos", - "version": "0.16.1", + "version": "0.17.0-alpha.1", "description": "Custom Cosmos client and utilities used by XChainJS clients", "keywords": [ "XChain", @@ -27,6 +27,7 @@ "clean": "rimraf lib/**", "build": "yarn clean && rollup -c", "test": "jest", + "e2e": "jest --config jest.config.e2e.js", "lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0", "prepublishOnly": "yarn build" }, @@ -34,8 +35,8 @@ "@xchainjs/xchain-client": "^0.11.1", "@xchainjs/xchain-crypto": "^0.2.4", "@xchainjs/xchain-util": "^0.5.1", + "@cosmos-client/core": "^0.45.1", "axios": "^0.25.0", - "cosmos-client": "0.39.2", "nock": "^13.0.5" }, "publishConfig": { @@ -45,7 +46,7 @@ "@xchainjs/xchain-client": "^0.11.1", "@xchainjs/xchain-crypto": "^0.2.4", "@xchainjs/xchain-util": "^0.5.1", - "axios": "^0.25.0", - "cosmos-client": "0.39.2" + "@cosmos-client/core": "^0.45.1", + "axios": "^0.25.0" } -} +} \ No newline at end of file diff --git a/packages/xchain-cosmos/src/client.ts b/packages/xchain-cosmos/src/client.ts index e3cb3493e..a468dd254 100644 --- a/packages/xchain-cosmos/src/client.ts +++ b/packages/xchain-cosmos/src/client.ts @@ -1,10 +1,11 @@ +import { proto } from '@cosmos-client/core' import { Address, Balance, + BaseXChainClient, FeeType, Fees, Network, - RootDerivationPaths, Tx, TxHash, TxHistoryParams, @@ -13,40 +14,34 @@ import { XChainClient, XChainClientParams, } from '@xchainjs/xchain-client' -import * as xchainCrypto from '@xchainjs/xchain-crypto' -import { Asset, assetToString, baseAmount } from '@xchainjs/xchain-util' -import { PrivKey } from 'cosmos-client' -import { StdTx } from 'cosmos-client/x/auth' +import { Asset, Chain, assetToString, baseAmount } from '@xchainjs/xchain-util' import { CosmosSDKClient } from './cosmos/sdk-client' import { TxOfflineParams } from './cosmos/types' import { AssetAtom, AssetMuon } from './types' -import { DECIMAL, getAsset, getDenom, getTxsFromHistory, registerCodecs } from './util' +import { DECIMAL, getAsset, getDenom, getTxsFromHistory } from './util' /** * Interface for custom Cosmos client */ export interface CosmosClient { getMainAsset(): Asset + getSDKClient(): CosmosSDKClient } const MAINNET_SDK = new CosmosSDKClient({ server: 'https://api.cosmos.network', - chainId: 'cosmoshub-3', + chainId: 'cosmoshub-4', }) const TESTNET_SDK = new CosmosSDKClient({ - server: 'http://lcd.gaia.bigdipper.live:1317', - chainId: 'gaia-3a', + server: 'https://rest.sentry-02.theta-testnet.polypore.xyz', + chainId: 'theta-testnet-001', }) /** * Custom Cosmos client */ -class Client implements CosmosClient, XChainClient { - private network: Network - private phrase = '' - private rootDerivationPaths: RootDerivationPaths - +class Client extends BaseXChainClient implements CosmosClient, XChainClient { private sdkClients: Map = new Map() /** @@ -64,51 +59,13 @@ class Client implements CosmosClient, XChainClient { phrase, rootDerivationPaths = { [Network.Mainnet]: `44'/118'/0'/0/`, - [Network.Testnet]: `44'/118'/1'/0/`, + [Network.Testnet]: `44'/118'/0'/0/`, [Network.Stagenet]: `44'/118'/0'/0/`, }, }: XChainClientParams) { - this.network = network - this.rootDerivationPaths = rootDerivationPaths + super(Chain.Cosmos, { network, rootDerivationPaths, phrase }) this.sdkClients.set(Network.Testnet, TESTNET_SDK) this.sdkClients.set(Network.Mainnet, MAINNET_SDK) - - if (phrase) this.setPhrase(phrase) - } - - /** - * Purge client. - * - * @returns {void} - */ - purgeClient(): void { - this.phrase = '' - } - - /** - * Set/update the current network. - * - * @param {Network} network - * @returns {void} - * - * @throws {"Network must be provided"} - * Thrown if network has not been set before. - */ - setNetwork(network: Network): void { - if (!network) { - throw new Error('Network must be provided') - } else { - this.network = network - } - } - - /** - * Get the current network. - * - * @returns {Network} - */ - getNetwork(): Network { - return this.network } /** @@ -122,7 +79,7 @@ class Client implements CosmosClient, XChainClient { case Network.Stagenet: return 'https://cosmos.bigdipper.live' case Network.Testnet: - return 'https://gaia.bigdipper.live' + return 'https://explorer.theta-testnet.polypore.xyz' } } @@ -146,27 +103,6 @@ class Client implements CosmosClient, XChainClient { return `${this.getExplorerUrl()}/transactions/${txID}` } - /** - * Set/update a new phrase - * - * @param {string} phrase A new phrase. - * @returns {Address} The address from the given phrase - * - * @throws {"Invalid phrase"} - * Thrown if the given phase is invalid. - */ - setPhrase(phrase: string, walletIndex = 0): Address { - if (this.phrase !== phrase) { - if (!xchainCrypto.validatePhrase(phrase)) { - throw new Error('Invalid phrase') - } - - this.phrase = phrase - } - - return this.getAddress(walletIndex) - } - /** * @private * Get private key. @@ -176,25 +112,16 @@ class Client implements CosmosClient, XChainClient { * @throws {"Phrase not set"} * Throws an error if phrase has not been set before * */ - private getPrivateKey(index = 0): PrivKey { + private getPrivateKey(index = 0): proto.cosmos.crypto.secp256k1.PrivKey { if (!this.phrase) throw new Error('Phrase not set') return this.getSDKClient().getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index)) } + getSDKClient(): CosmosSDKClient { return this.sdkClients.get(this.network) || TESTNET_SDK } - /** - * Get getFullDerivationPath - * - * @param {number} index the HD wallet index - * @returns {string} The bitcoin derivation path based on the network. - */ - getFullDerivationPath(index: number): string { - return this.rootDerivationPaths[this.network] + `${index}` - } - /** * Get the current address. * @@ -270,8 +197,6 @@ class Client implements CosmosClient, XChainClient { const txMinHeight = undefined const txMaxHeight = undefined - registerCodecs() - const mainAsset = this.getMainAsset() const txHistory = await this.getSDKClient().searchTx({ messageAction, @@ -283,8 +208,8 @@ class Client implements CosmosClient, XChainClient { }) return { - total: parseInt(txHistory.total_count?.toString() || '0'), - txs: getTxsFromHistory(txHistory.txs || [], mainAsset), + total: parseInt(txHistory.pagination?.total || '0'), + txs: getTxsFromHistory(txHistory.tx_responses || [], mainAsset), } } @@ -296,6 +221,11 @@ class Client implements CosmosClient, XChainClient { */ async getTransactionData(txId: string): Promise { const txResult = await this.getSDKClient().txsHashGet(txId) + + if (!txResult || txResult.txhash === '') { + throw new Error('transaction not found') + } + const txs = getTxsFromHistory([txResult], this.getMainAsset()) if (txs.length === 0) throw new Error('transaction not found') @@ -310,10 +240,9 @@ class Client implements CosmosClient, XChainClient { */ async transfer({ walletIndex, asset, amount, recipient, memo }: TxParams): Promise { const fromAddressIndex = walletIndex || 0 - registerCodecs() const mainAsset = this.getMainAsset() - const transferResult = await this.getSDKClient().transfer({ + return this.getSDKClient().transfer({ privkey: this.getPrivateKey(fromAddressIndex), from: this.getAddress(fromAddressIndex), to: recipient, @@ -321,15 +250,13 @@ class Client implements CosmosClient, XChainClient { asset: getDenom(asset || mainAsset), memo, }) - - return transferResult?.txhash || '' } /** * Transfer offline balances. * * @param {TxOfflineParams} params The transfer offline options. - * @returns {StdTx} The signed transaction. + * @returns {string} The signed transaction bytes. */ async transferOffline({ walletIndex, @@ -339,9 +266,8 @@ class Client implements CosmosClient, XChainClient { memo, from_account_number, from_sequence, - }: TxOfflineParams): Promise { + }: TxOfflineParams): Promise { const fromAddressIndex = walletIndex || 0 - registerCodecs() const mainAsset = this.getMainAsset() return await this.getSDKClient().transferSignedOffline({ diff --git a/packages/xchain-cosmos/src/cosmos/sdk-client.ts b/packages/xchain-cosmos/src/cosmos/sdk-client.ts index 10d31ccb4..65ec42907 100644 --- a/packages/xchain-cosmos/src/cosmos/sdk-client.ts +++ b/packages/xchain-cosmos/src/cosmos/sdk-client.ts @@ -1,18 +1,15 @@ -import { TxHistoryParams } from '@xchainjs/xchain-client' +import { cosmosclient, proto, rest } from '@cosmos-client/core' +import { TxHash, TxHistoryParams } from '@xchainjs/xchain-client' import * as xchainCrypto from '@xchainjs/xchain-crypto' import axios from 'axios' import * as BIP32 from 'bip32' -import { AccAddress, CosmosSDK, Msg, PrivKey, PrivKeySecp256k1 } from 'cosmos-client' -import { BroadcastTxCommitResult, Coin, StdTxSignature } from 'cosmos-client/api' -import { BaseAccount, StdTx, auth } from 'cosmos-client/x/auth' -import { MsgSend, bank } from 'cosmos-client/x/bank' import { getQueryString } from '../util' import { APIQueryParam, - BaseAccountResponse, CosmosSDKClientParams, + GetTxByHashResponse, RPCResponse, RPCTxSearchResult, SearchTxParams, @@ -20,10 +17,15 @@ import { TransferParams, TxHistoryResponse, TxResponse, + UnsignedTxParams, } from './types' +const DEFAULT_FEE = new proto.cosmos.tx.v1beta1.Fee({ + amount: [], + gas_limit: cosmosclient.Long.fromString('300000'), +}) export class CosmosSDKClient { - sdk: CosmosSDK + sdk: cosmosclient.CosmosSDK server: string chainId: string @@ -34,8 +36,9 @@ export class CosmosSDKClient { constructor({ server, chainId, prefix = 'cosmos' }: CosmosSDKClientParams) { this.server = server this.chainId = chainId - this.prefix = prefix - this.sdk = new CosmosSDK(this.server, this.chainId) + this.sdk = new cosmosclient.CosmosSDK(server, this.chainId) + + this.updatePrefix(prefix) } updatePrefix(prefix: string) { @@ -44,37 +47,38 @@ export class CosmosSDKClient { } setPrefix(): void { - AccAddress.setBech32Prefix( - this.prefix, - this.prefix + 'pub', - this.prefix + 'valoper', - this.prefix + 'valoperpub', - this.prefix + 'valcons', - this.prefix + 'valconspub', - ) + cosmosclient.config.setBech32Prefix({ + accAddr: this.prefix, + accPub: this.prefix + 'pub', + valAddr: this.prefix + 'valoper', + valPub: this.prefix + 'valoperpub', + consAddr: this.prefix + 'valcons', + consPub: this.prefix + 'valconspub', + }) } - getAddressFromPrivKey(privkey: PrivKey): string { + getAddressFromPrivKey(privkey: proto.cosmos.crypto.secp256k1.PrivKey): string { this.setPrefix() - return AccAddress.fromPublicKey(privkey.getPubKey()).toBech32() + return cosmosclient.AccAddress.fromPublicKey(privkey.pubKey()).toString() } getAddressFromMnemonic(mnemonic: string, derivationPath: string): string { this.setPrefix() const privKey = this.getPrivKeyFromMnemonic(mnemonic, derivationPath) - return AccAddress.fromPublicKey(privKey.getPubKey()).toBech32() + return cosmosclient.AccAddress.fromPublicKey(privKey.pubKey()).toString() } - getPrivKeyFromMnemonic(mnemonic: string, derivationPath: string): PrivKey { + getPrivKeyFromMnemonic(mnemonic: string, derivationPath: string): proto.cosmos.crypto.secp256k1.PrivKey { + this.setPrefix() const seed = xchainCrypto.getSeed(mnemonic) const node = BIP32.fromSeed(seed) const child = node.derivePath(derivationPath) if (!child.privateKey) throw new Error('child does not have a privateKey') - return new PrivKeySecp256k1(child.privateKey) + return new proto.cosmos.crypto.secp256k1.PrivKey({ key: child.privateKey }) } checkAddress(address: string): boolean { @@ -83,34 +87,63 @@ export class CosmosSDKClient { if (!address.startsWith(this.prefix)) return false try { - return AccAddress.fromBech32(address).toBech32() === address + return cosmosclient.AccAddress.fromString(address).toString() === address } catch (err) { return false } } - async getBalance(address: string): Promise { - this.setPrefix() + getUnsignedTxBody({ from, to, amount, asset, memo = '' }: UnsignedTxParams): proto.cosmos.tx.v1beta1.TxBody { + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: from, + to_address: to, + amount: [ + { + amount: amount, + denom: asset, + }, + ], + }) - const accAddress = AccAddress.fromBech32(address) + return new proto.cosmos.tx.v1beta1.TxBody({ + messages: [cosmosclient.codec.packAny(msgSend)], + memo, + }) + } - return (await bank.balancesAddressGet(this.sdk, accAddress)).data.result + async getBalance(address: string): Promise { + this.setPrefix() + + const accAddress = cosmosclient.AccAddress.fromString(address) + const response = await rest.bank.allBalances(this.sdk, accAddress) + return response.data.balances as proto.cosmos.base.v1beta1.Coin[] } - async searchTx({ - messageAction, - messageSender, - page, - limit, - txMinHeight, - txMaxHeight, - }: SearchTxParams): Promise { + async getAccount(address: cosmosclient.AccAddress): Promise { + const account = await rest.auth + .account(this.sdk, address) + .then((res) => res.data.account && cosmosclient.codec.unpackCosmosAny(res.data.account)) + .catch((_) => undefined) + if (!(account instanceof proto.cosmos.auth.v1beta1.BaseAccount)) { + throw Error('could not get account') + } + return account + } + async searchTx({ messageAction, messageSender, page, limit }: SearchTxParams): Promise { const queryParameter: APIQueryParam = {} + + if (!messageAction && !messageSender) { + throw new Error('One of messageAction or messageSender must be specified') + } + + let eventsParam = '' + if (messageAction !== undefined) { - queryParameter['message.action'] = messageAction + eventsParam = `message.action='${messageAction}'` } if (messageSender !== undefined) { - queryParameter['message.sender'] = messageSender + const prefix = eventsParam.length > 0 ? ',' : '' + eventsParam = `${eventsParam}${prefix}message.sender='${messageSender}'` } if (page !== undefined) { queryParameter['page'] = page.toString() @@ -118,16 +151,13 @@ export class CosmosSDKClient { if (limit !== undefined) { queryParameter['limit'] = limit.toString() } - if (txMinHeight !== undefined) { - queryParameter['tx.minheight'] = txMinHeight.toString() - } - if (txMaxHeight !== undefined) { - queryParameter['tx.maxheight'] = txMaxHeight.toString() - } + + queryParameter['events'] = eventsParam this.setPrefix() - return (await axios.get(`${this.server}/txs?${getQueryString(queryParameter)}`)).data + return (await axios.get(`${this.server}/cosmos/tx/v1beta1/txs?${getQueryString(queryParameter)}`)) + .data } async searchTxFromRPC({ @@ -184,96 +214,115 @@ export class CosmosSDKClient { async txsHashGet(hash: string): Promise { this.setPrefix() - return (await axios.get(`${this.server}/txs/${hash}`)).data + return (await axios.get(`${this.server}/cosmos/tx/v1beta1/txs/${hash}`)).data.tx_response } - unsignedStdTxGet({ - from, - to, - amount, - asset, - memo = '', - fee = { - amount: [], - gas: '200000', - }, - }: TransferParams) { + async transfer({ privkey, from, to, amount, asset, memo = '', fee = DEFAULT_FEE }: TransferParams): Promise { this.setPrefix() - const msg: Msg = [ - MsgSend.fromJSON({ - from_address: from, - to_address: to, - amount: [ - { - amount: amount.toString(), - denom: asset, - }, - ], - }), - ] - const signatures: StdTxSignature[] = [] + const msgSend = new proto.cosmos.bank.v1beta1.MsgSend({ + from_address: from, + to_address: to, + amount: [ + { + amount: amount, + denom: asset, + }, + ], + }) - return StdTx.fromJSON({ - msg, - fee, - signatures, + const pubKey = privkey.pubKey() + const signer = cosmosclient.AccAddress.fromPublicKey(pubKey) + + const account = await this.getAccount(signer) + + const txBody = new proto.cosmos.tx.v1beta1.TxBody({ + messages: [cosmosclient.codec.packAny(msgSend)], memo, }) + + const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({ + signer_infos: [ + { + public_key: cosmosclient.codec.packAny(pubKey), + mode_info: { + single: { + mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT, + }, + }, + sequence: account.sequence, + }, + ], + fee, + }) + + const txBuilder = new cosmosclient.TxBuilder(this.sdk, txBody, authInfo) + + return this.signAndBroadcast(txBuilder, privkey, account) } - async transfer({ + async transferSignedOffline({ privkey, from, + from_account_number = '0', + from_sequence = '0', to, amount, asset, memo = '', - fee = { - amount: [], - gas: '200000', - }, - }: TransferParams): Promise { - const unsignedStdTx = this.unsignedStdTxGet({ privkey, from, to, amount, asset, memo, fee }) - - return this.signAndBroadcast(unsignedStdTx, privkey, AccAddress.fromBech32(from)) + fee = DEFAULT_FEE, + }: TransferOfflineParams): Promise { + const txBody = this.getUnsignedTxBody({ from, to, amount, asset, memo }) + + const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({ + signer_infos: [ + { + public_key: cosmosclient.codec.packAny(privkey.pubKey()), + mode_info: { + single: { + mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT, + }, + }, + sequence: cosmosclient.Long.fromString(from_sequence), + }, + ], + fee, + }) + + const txBuilder = new cosmosclient.TxBuilder(this.sdk, txBody, authInfo) + + const signDocBytes = txBuilder.signDocBytes(cosmosclient.Long.fromString(from_account_number)) + txBuilder.addSignature(privkey.sign(signDocBytes)) + return txBuilder.txBytes() } - async signAndBroadcast(unsignedStdTx: StdTx, privkey: PrivKey, signer: AccAddress): Promise { + async signAndBroadcast( + txBuilder: cosmosclient.TxBuilder, + privKey: proto.cosmos.crypto.secp256k1.PrivKey, + signerAccount: proto.cosmos.auth.v1beta1.IBaseAccount, + ): Promise { this.setPrefix() - let account: BaseAccount = (await auth.accountsAddressGet(this.sdk, signer)).data.result - if (account.account_number === undefined) { - account = BaseAccount.fromJSON((account as BaseAccountResponse).value) - } + if (!signerAccount || !signerAccount.account_number) throw new Error('Invalid Account') - const signedStdTx = auth.signStdTx( - this.sdk, - privkey, - unsignedStdTx, - account.account_number.toString(), - account.sequence.toString(), - ) + // sign + const signDocBytes = txBuilder.signDocBytes(signerAccount.account_number) + txBuilder.addSignature(privKey.sign(signDocBytes)) - return (await auth.txsPost(this.sdk, signedStdTx, 'sync')).data - } + // broadcast + const res = await rest.tx.broadcastTx(this.sdk, { + tx_bytes: txBuilder.txBytes(), + mode: rest.tx.BroadcastTxMode.Sync, + }) - async transferSignedOffline({ - privkey, - from, - from_account_number = '0', - from_sequence = '0', - to, - amount, - asset, - memo = '', - fee = { - amount: [], - gas: '200000', - }, - }: TransferOfflineParams): Promise { - const unsignedStdTx = this.unsignedStdTxGet({ privkey, from, to, amount, asset, memo, fee }) - - return auth.signStdTx(this.sdk, privkey, unsignedStdTx, from_account_number, from_sequence) + if (res?.data?.tx_response?.code !== 0) { + throw new Error('Error broadcasting: ' + res?.data?.tx_response?.raw_log) + } + + if (!res.data?.tx_response.txhash || res.data?.tx_response.txhash === '') { + throw new Error('Error broadcasting, txhash not present on response') + } + + return res.data.tx_response.txhash } } diff --git a/packages/xchain-cosmos/src/cosmos/types.ts b/packages/xchain-cosmos/src/cosmos/types.ts index fd08b1826..03bcdd9b5 100644 --- a/packages/xchain-cosmos/src/cosmos/types.ts +++ b/packages/xchain-cosmos/src/cosmos/types.ts @@ -1,8 +1,5 @@ +import { proto } from '@cosmos-client/core' import { TxParams } from '@xchainjs/xchain-client' -import { BigSource } from 'big.js' -import { Msg, PrivKey, codec } from 'cosmos-client' -import { StdTxFee } from 'cosmos-client/api' -import { BaseAccount, StdTx } from 'cosmos-client/x/auth' export type CosmosSDKClientParams = { server: string @@ -21,14 +18,22 @@ export type SearchTxParams = { txMaxHeight?: number } +export type UnsignedTxParams = { + from: string + to: string + amount: string + asset: string + memo?: string +} + export type TransferParams = { - privkey: PrivKey + privkey: proto.cosmos.crypto.secp256k1.PrivKey from: string to: string - amount: BigSource + amount: string asset: string memo?: string - fee?: StdTxFee + fee?: proto.cosmos.tx.v1beta1.Fee } export type TransferOfflineParams = TransferParams & { @@ -43,12 +48,12 @@ export type TxOfflineParams = TxParams & { export type BaseAccountResponse = { type?: string - value?: BaseAccount + value?: proto.cosmos.auth.v1beta1.BaseAccount } export type RawTxResponse = { body: { - messages: Msg[] + messages: proto.cosmos.bank.v1beta1.MsgSend[] } } @@ -68,6 +73,10 @@ export type TxLog = { events: TxEvent[] } +export type GetTxByHashResponse = { + tx_response: TxResponse +} + export type TxResponse = { height?: number txhash?: string @@ -76,17 +85,18 @@ export type TxResponse = { logs?: TxLog[] gas_wanted?: string gas_used?: string - tx?: StdTx | RawTxResponse | codec.AminoWrapping + tx?: RawTxResponse timestamp: string } export type TxHistoryResponse = { - total_count?: number - count?: number page_number?: number page_total?: number limit?: number - txs?: TxResponse[] + pagination?: { + total: string + } + tx_responses?: TxResponse[] } export type APIQueryParam = { diff --git a/packages/xchain-cosmos/src/util.ts b/packages/xchain-cosmos/src/util.ts index f265d4e87..ca7e5d2ac 100644 --- a/packages/xchain-cosmos/src/util.ts +++ b/packages/xchain-cosmos/src/util.ts @@ -1,8 +1,6 @@ +import { cosmosclient, proto } from '@cosmos-client/core' import { FeeType, Fees, Tx, TxFrom, TxTo, TxType } from '@xchainjs/xchain-client' import { Asset, assetToString, baseAmount } from '@xchainjs/xchain-util' -import { Msg, codec } from 'cosmos-client' -import { StdTx } from 'cosmos-client/x/auth' -import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank' import { APIQueryParam, RawTxResponse, TxResponse } from './cosmos/types' import { AssetAtom, AssetMuon } from './types' @@ -18,10 +16,10 @@ export const DECIMAL = 6 * @param {Msg} msg * @returns {boolean} `true` or `false`. */ -export const isMsgSend = (msg: Msg): msg is MsgSend => - (msg as MsgSend)?.amount !== undefined && - (msg as MsgSend)?.from_address !== undefined && - (msg as MsgSend)?.to_address !== undefined +export const isMsgSend = (msg: unknown): msg is proto.cosmos.bank.v1beta1.MsgSend => + (msg as proto.cosmos.bank.v1beta1.MsgSend)?.amount !== undefined && + (msg as proto.cosmos.bank.v1beta1.MsgSend)?.from_address !== undefined && + (msg as proto.cosmos.bank.v1beta1.MsgSend)?.to_address !== undefined /** * Type guard for MsgMultiSend @@ -29,8 +27,9 @@ export const isMsgSend = (msg: Msg): msg is MsgSend => * @param {Msg} msg * @returns {boolean} `true` or `false`. */ -export const isMsgMultiSend = (msg: Msg): msg is MsgMultiSend => - (msg as MsgMultiSend)?.inputs !== undefined && (msg as MsgMultiSend)?.outputs !== undefined +export const isMsgMultiSend = (msg: unknown): msg is proto.cosmos.bank.v1beta1.MsgMultiSend => + (msg as proto.cosmos.bank.v1beta1.MsgMultiSend)?.inputs !== undefined && + (msg as proto.cosmos.bank.v1beta1.MsgMultiSend)?.outputs !== undefined /** * Get denomination from Asset @@ -56,6 +55,13 @@ export const getAsset = (denom: string): Asset | null => { return null } +const getCoinAmount = (coins?: proto.cosmos.base.v1beta1.ICoin[]) => { + return coins + ? coins + .map((coin) => baseAmount(coin.amount || 0, DECIMAL)) + .reduce((acc, cur) => baseAmount(acc.amount().plus(cur.amount()), DECIMAL), baseAmount(0, DECIMAL)) + : baseAmount(0, DECIMAL) +} /** * Parse transaction type * @@ -65,58 +71,55 @@ export const getAsset = (denom: string): Asset | null => { */ export const getTxsFromHistory = (txs: TxResponse[], mainAsset: Asset): Tx[] => { return txs.reduce((acc, tx) => { - let msgs: Msg[] = [] + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let msgs: Array if ((tx.tx as RawTxResponse).body === undefined) { - msgs = codec.fromJSONString(codec.toJSONString(tx.tx as StdTx)).msg + msgs = cosmosclient.codec.packAnyFromCosmosJSON(tx.tx).msg } else { - msgs = codec.fromJSONString(codec.toJSONString((tx.tx as RawTxResponse).body.messages)) + msgs = cosmosclient.codec.packAnyFromCosmosJSON((tx.tx as RawTxResponse).body.messages) } const from: TxFrom[] = [] const to: TxTo[] = [] msgs.map((msg) => { if (isMsgSend(msg)) { - const msgSend = msg as MsgSend - const amount = msgSend.amount - .map((coin) => baseAmount(coin.amount, 6)) - .reduce((acc, cur) => baseAmount(acc.amount().plus(cur.amount()), 6), baseAmount(0, 6)) + const msgSend = msg + const amount = getCoinAmount(msgSend.amount) let from_index = -1 from.forEach((value, index) => { - if (value.from === msgSend.from_address.toBech32()) from_index = index + if (value.from === msgSend.from_address) from_index = index }) if (from_index === -1) { from.push({ - from: msgSend.from_address.toBech32(), + from: msgSend.from_address, amount, }) } else { - from[from_index].amount = baseAmount(from[from_index].amount.amount().plus(amount.amount()), 6) + from[from_index].amount = baseAmount(from[from_index].amount.amount().plus(amount.amount()), DECIMAL) } let to_index = -1 to.forEach((value, index) => { - if (value.to === msgSend.to_address.toBech32()) to_index = index + if (value.to === msgSend.to_address) to_index = index }) if (to_index === -1) { to.push({ - to: msgSend.to_address.toBech32(), + to: msgSend.to_address, amount, }) } else { - to[to_index].amount = baseAmount(to[to_index].amount.amount().plus(amount.amount()), 6) + to[to_index].amount = baseAmount(to[to_index].amount.amount().plus(amount.amount()), DECIMAL) } } else if (isMsgMultiSend(msg)) { - const msgMultiSend = msg as MsgMultiSend + const msgMultiSend = msg msgMultiSend.inputs.map((input) => { - const amount = input.coins - .map((coin) => baseAmount(coin.amount, 6)) - .reduce((acc, cur) => baseAmount(acc.amount().plus(cur.amount()), 6), baseAmount(0, 6)) + const amount = getCoinAmount(input.coins || []) let from_index = -1 @@ -126,18 +129,16 @@ export const getTxsFromHistory = (txs: TxResponse[], mainAsset: Asset): Tx[] => if (from_index === -1) { from.push({ - from: input.address, + from: input.address || '', amount, }) } else { - from[from_index].amount = baseAmount(from[from_index].amount.amount().plus(amount.amount()), 6) + from[from_index].amount = baseAmount(from[from_index].amount.amount().plus(amount.amount()), DECIMAL) } }) msgMultiSend.outputs.map((output) => { - const amount = output.coins - .map((coin) => baseAmount(coin.amount, 6)) - .reduce((acc, cur) => baseAmount(acc.amount().plus(cur.amount()), 6), baseAmount(0, 6)) + const amount = getCoinAmount(output.coins || []) let to_index = -1 @@ -147,11 +148,11 @@ export const getTxsFromHistory = (txs: TxResponse[], mainAsset: Asset): Tx[] => if (to_index === -1) { to.push({ - to: output.address, + to: output.address || '', amount, }) } else { - to[to_index].amount = baseAmount(to[to_index].amount.amount().plus(amount.amount()), 6) + to[to_index].amount = baseAmount(to[to_index].amount.amount().plus(amount.amount()), DECIMAL) } }) } @@ -184,16 +185,6 @@ export const getQueryString = (params: APIQueryParam): string => { .join('&') } -/** - * Register message codecs. - * - * @returns {void} - */ -export const registerCodecs = () => { - codec.registerCodec('cosmos-sdk/MsgSend', MsgSend, MsgSend.fromJSON) - codec.registerCodec('cosmos-sdk/MsgMultiSend', MsgMultiSend, MsgMultiSend.fromJSON) -} - /** * Get the default fee. * diff --git a/packages/xchain-thorchain/CHANGELOG.md b/packages/xchain-thorchain/CHANGELOG.md index 608a90df7..2f6f35db5 100644 --- a/packages/xchain-thorchain/CHANGELOG.md +++ b/packages/xchain-thorchain/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.24.0 (2022-03-15) + +## Breaking Changes + +- `buildDepositTx` now returns `proto.cosmos.tx.v1beta1.TxBody` from `@cosmos-client/core` + # v0.23.0 (2022-03-08) ## Add diff --git a/packages/xchain-thorchain/README.md b/packages/xchain-thorchain/README.md index d297c96aa..8d1cb9cec 100644 --- a/packages/xchain-thorchain/README.md +++ b/packages/xchain-thorchain/README.md @@ -11,10 +11,10 @@ yarn add @xchainjs/xchain-thorchain Following peer dependencies have to be installed into your project. These are not included in `@xchainjs/xchain-thorchain`. ``` -yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util @xchainjs/xchain-cosmos axios cosmos-client +yarn add @xchainjs/xchain-client @xchainjs/xchain-crypto @xchainjs/xchain-util @xchainjs/xchain-cosmos axios cosmos-client bech32-buffer ``` -Important note: Make sure to install same version of `cosmos-client` as `xchain-thorchain` is using (currently `cosmos-client@0.39.2` ). In other case things might break. +Important note: Make sure to install same version of `@cosmos-client/core` as `xchain-thorchain` is using (currently `@cosmos-client/core@0.45.1` ). In other case things might break. ## Thorchain Client Testing @@ -44,23 +44,11 @@ Rate limits: No import { Client } from '@xchainjs/xchain-thorchain' // Create a `Client` -// Note: `chainIds` are required -const chainIds = getChainIds(getDefaultClientUrl()) // instead of `getDefaultClientUrl` you can pass custom API endpoints -const client = new Client({ network: Network.Testnet, phrase: 'my secret phrase', chainIds }) +const client = new Client({ network: Network.Testnet, phrase: 'my secret phrase' }) // get address const address = client.getAddress() -console.log('address:', address) // address: tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg - -// get private key -const privKey = client.getPrivKey() -console.log('privKey:', privKey.toBase64()) // privKey: {your-private-key} base64 encoded -console.log('privKey:', privKey.toBuffer()) // privKey: {your-private-key} as `Buffer` - -// get public key -const pubKey = client.getPubKey() -console.log('pubKey:', pubKey.toBase64()) // pubKey: {your-public-key} base64 encoded -console.log('pubKey:', pubKey.toBuffer()) // pubKey: {your-public-key} as `Buffer` +console.log('address:', client.getAddress()) // address: tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg // get balances const balances = await client.getBalance(address) @@ -76,3 +64,20 @@ console.log('tx asset:', tx.asset) // tx asset: { chain: 'THOR', symbol: 'RUNE', ``` For more examples check out tests in `./__tests__/client.test.ts` + +## Creating protobuffer typescript bindings + +In order for this library to de/serialize proto3 structures, you can use the following to create bindings + +1. `git clone https://gitlab.com/thorchain/thornode` +2. run the following (adjust the paths acordingly) to generate a typecript file for MsgDeposit + ```bash + yarn run pbjs -w commonjs -t static-module /thornode/proto/thorchain/v1/x/thorchain/types/msg_deposit.proto /thornode/proto/thorchain/v1/common/common.proto /thornode/proto/thorchain/v1/x/thorchain/types/msg_send.proto /thornode/third_party/proto/cosmos/base/v1beta1/coin.proto -o src/types/proto/MsgCompiled.js + ``` +3. run the following to generate the .d.ts file + ```bash + yarn run pbts src/types/proto/MsgCompiled.js -o src/types/proto/MsgCompiled.d.ts + ``` + +Alternatively, you can run the convenience script: `genMsgs.sh`, which will overwrite the proto/js files in types/proto. This should only be done and checked in if changes were made to the upstream Msg in the THORNode repo. + diff --git a/packages/xchain-thorchain/__e2e__/thorchain-client.e2e.ts b/packages/xchain-thorchain/__e2e__/thorchain-client.e2e.ts new file mode 100644 index 000000000..e86d87295 --- /dev/null +++ b/packages/xchain-thorchain/__e2e__/thorchain-client.e2e.ts @@ -0,0 +1,77 @@ +import { Client as BnbClient } from '@xchainjs/xchain-binance' +import { Network, TxParams, XChainClient } from '@xchainjs/xchain-client' +import { Client as ThorClient, ThorchainClient } from '@xchainjs/xchain-thorchain' +import { Asset, AssetRuneNative, BaseAmount, assetToString, baseAmount, delay } from '@xchainjs/xchain-util' + +export type Swap = { + fromBaseAmount: BaseAmount + to: Asset +} + +// Mock chain ids +const chainIds = { + [Network.Mainnet]: 'chain-id-mainnet', + [Network.Stagenet]: 'chain-id-stagenet', + [Network.Testnet]: 'thorchain-testnet-v2', +} + +const thorClient: XChainClient = new ThorClient({ network: Network.Testnet, phrase: process.env.PHRASE, chainIds: chainIds }) +const thorchainClient = thorClient as unknown as ThorchainClient +const bnbClient: XChainClient = new BnbClient({ network: Network.Testnet, phrase: process.env.PHRASE }) + +describe('thorchain Integration Tests', () => { + it('should fetch thorchain balances', async () => { + const address = thorClient.getAddress(0) + const balances = await thorClient.getBalance(address) + balances.forEach((bal) => { + console.log(`${assetToString(bal.asset)} = ${bal.amount.amount()}`) + }) + expect(balances.length).toBeGreaterThan(0) + }) + it('should xfer rune from wallet 0 -> 1, with a memo', async () => { + try { + const addressTo = thorClient.getAddress(1) + const transferTx: TxParams = { + walletIndex: 0, + asset: AssetRuneNative, + amount: baseAmount('100'), + recipient: addressTo, + memo: 'Hi!', + } + const hash = await thorClient.transfer(transferTx) + expect(hash.length).toBeGreaterThan(0) + } catch (error) { + console.log(error) + throw error + } + }) + it('should swap some rune for BNB', async () => { + try { + + // Wait 10 seconds, make sure previous test has finished to avoid sequnce conflict + await delay(10 * 1000) + + const address = await bnbClient.getAddress() + const memo = `=:BNB.BNB:${address}` + + const hash = await thorchainClient.deposit({ + walletIndex: 0, + amount: baseAmount('100'), + asset: AssetRuneNative, + memo, + }) + + expect(hash.length).toBeGreaterThan(5) + + } catch (error) { + console.log(error) + throw error + } + }) + it('should fetch thorchain txs', async () => { + const address = thorClient.getAddress(0) + const txPage = await thorClient.getTransactions({ address }) + expect(txPage.total).toBeGreaterThan(0) + expect(txPage.txs.length).toBeGreaterThan(0) + }) +}) diff --git a/packages/xchain-thorchain/__tests__/client.test.ts b/packages/xchain-thorchain/__tests__/client.test.ts index fa44eccb4..4d306e9d5 100644 --- a/packages/xchain-thorchain/__tests__/client.test.ts +++ b/packages/xchain-thorchain/__tests__/client.test.ts @@ -1,3 +1,4 @@ +import { proto } from '@cosmos-client/core' import { Network, TxsPage } from '@xchainjs/xchain-client' import { CosmosSDKClient, RPCResponse, RPCTxSearchResult, TxResponse } from '@xchainjs/xchain-cosmos' import { @@ -10,12 +11,10 @@ import { assetToBase, baseAmount, } from '@xchainjs/xchain-util' -import { BaseAccount, BroadcastTxCommitResult, Coin } from 'cosmos-client/api' import nock from 'nock' import { mockTendermintNodeInfo } from '../__mocks__/thornode-api' import { Client } from '../src/client' -import { ThorchainDepositResponse } from '../src/types' // Mock chain ids const chainIds = { @@ -28,26 +27,38 @@ const mockAccountsAddress = ( url: string, address: string, result: { - height: number - result: BaseAccount + account: { + '@type': string + address: string + pub_key?: { + '@type': string + key: string + } + account_number: string + sequence: string + } }, ) => { - nock(url).get(`/auth/accounts/${address}`).reply(200, result) + nock(url).get(`/cosmos/auth/v1beta1/accounts/${address}`).reply(200, result) +} + +const mockGetChainId = (url: string, chainId: string) => { + const response = { + default_node_info: { + network: chainId, + }, + } + nock(url).get('/cosmos/base/tendermint/v1beta1/node_info').reply(200, response) } const mockAccountsBalance = ( url: string, address: string, result: { - height: number - result: Coin[] + balances: proto.cosmos.base.v1beta1.Coin[] }, ) => { - nock(url).get(`/bank/balances/${address}`).reply(200, result) -} - -const mockThorchainDeposit = (url: string, result: ThorchainDepositResponse) => { - nock(url).post('/thorchain/deposit').reply(200, result) + nock(url).get(`/cosmos/bank/v1beta1/balances/${address}`).reply(200, result) } const mockThorchainConstants = (url: string) => { @@ -55,11 +66,19 @@ const mockThorchainConstants = (url: string) => { nock(url).get('/thorchain/constants').reply(200, response) } -const assertTxsPost = (url: string, memo: undefined | string, result: BroadcastTxCommitResult): void => { - nock(url) - .post(`/txs`, (body) => { - expect(body.tx.msg.length).toEqual(1) - expect(body.tx.memo).toEqual(memo) +const assertTxsPost = ( + url: string, + result: { + tx_response: { + txhash: string + code: number + } + }, +): void => { + nock(url, { allowUnmocked: true }) + .post(`/cosmos/tx/v1beta1/txs`, (body) => { + expect(body.mode).toEqual('BROADCAST_MODE_SYNC') + expect(body.tx_bytes.length).toBeGreaterThan(0) return true }) .reply(200, result) @@ -73,8 +92,8 @@ const mockTxHistory = (url: string, result: RPCResponse): voi .reply(200, result) } -const assertTxHashGet = (url: string, hash: string, result: TxResponse): void => { - nock(url).get(`/txs/${hash}`).reply(200, result) +const assertTxHashGet = (url: string, hash: string, result: { tx_response: TxResponse }): void => { + nock(url).get(`/cosmos/tx/v1beta1/txs/${hash}`).reply(200, result) } describe('Client Test', () => { @@ -89,6 +108,7 @@ describe('Client Test', () => { beforeEach(() => { thorClient = new Client({ phrase, network: Network.Testnet, chainIds }) thorMainClient = new Client({ phrase, network: Network.Mainnet, chainIds }) + mockGetChainId(thorClient.getClientUrl().node, chainIds[Network.Testnet]) }) afterEach(() => { @@ -211,8 +231,8 @@ describe('Client Test', () => { }) it('returns private key', async () => { - const privKey = thorClient.getPrivKey() - expect(privKey.toBase64()).toEqual('CHCbyYWorMZVRFtfJzt72DigvZeRNi3jo2c3hGEQ46I=') + const privKey = thorClient.getPrivateKey() + expect(Buffer.from(privKey.bytes()).toString('base64')).toEqual('CHCbyYWorMZVRFtfJzt72DigvZeRNi3jo2c3hGEQ46I=') }) describe('chainId', () => { @@ -273,13 +293,13 @@ describe('Client Test', () => { it('returns public key', async () => { const pubKey = thorClient.getPubKey() - expect(pubKey.toBase64()).toEqual('AsL4F+rvFMqDkZYpVVnZa0OBa0EXwscjNrODbBME42vC') + const pkString = Buffer.from(pubKey.bytes()).toString('base64') + expect(pkString).toEqual('AsL4F+rvFMqDkZYpVVnZa0OBa0EXwscjNrODbBME42vC') }) it('has no balances', async () => { mockAccountsBalance(thorClient.getClientUrl().node, testnet_address_path0, { - height: 0, - result: [], + balances: [], }) const result = await thorClient.getBalance(thorClient.getAddress(0)) expect(result).toEqual([]) @@ -290,12 +310,11 @@ describe('Client Test', () => { // mainnet - has balance: thor147jegk6e9sum7w3svy3hy4qme4h6dqdkgxhda5 // mainnet - 0: thor19kacmmyuf2ysyvq3t9nrl9495l5cvktjs0yfws mockAccountsBalance(thorMainClient.getClientUrl().node, 'thor147jegk6e9sum7w3svy3hy4qme4h6dqdkgxhda5', { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'rune', amount: '100', - }, + }), ], }) @@ -308,20 +327,19 @@ describe('Client Test', () => { it('rune + synth balances', async () => { thorClient.setNetwork(Network.Testnet) mockAccountsBalance(thorClient.getClientUrl().node, 'tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg', { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'bnb/bnb', amount: '100', - }, - { + }), + new proto.cosmos.base.v1beta1.Coin({ denom: 'bnb/busd-74e', amount: '200', - }, - { + }), + new proto.cosmos.base.v1beta1.Coin({ denom: 'rune', amount: '200', - }, + }), ], }) @@ -342,20 +360,19 @@ describe('Client Test', () => { const BUSD_ASSET_SYNTH: Asset = { chain: BNBChain, symbol: 'BUSD-74E', ticker: 'BUSD', synth: true } thorClient.setNetwork(Network.Testnet) mockAccountsBalance(thorClient.getClientUrl().node, 'tthor13gym97tmw3axj3hpewdggy2cr288d3qffr8skg', { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'bnb/bnb', amount: '100', - }, - { + }), + new proto.cosmos.base.v1beta1.Coin({ denom: 'bnb/busd-74e', amount: '200', - }, - { + }), + new proto.cosmos.base.v1beta1.Coin({ denom: 'rune', amount: '200', - }, + }), ], }) @@ -395,7 +412,7 @@ describe('Client Test', () => { const txHash = '9C175AF7ACE9FCDC930B78909FFF598C18CBEAF9F39D7AA2C4D9A27BB7E55A5C' mockTxHistory(thorClient.getClientUrl().rpc, historyData) - assertTxHashGet(thorClient.getClientUrl().node, txHash, bondTxData) + assertTxHashGet(thorClient.getClientUrl().node, txHash, { tx_response: bondTxData }) const txs = await thorClient.getTransactions({ address: 'tthor137kees65jmhjm3gxyune0km5ea0zkpnj4lw29f', @@ -424,40 +441,37 @@ describe('Client Test', () => { const memo = 'transfer' const expected_txsPost_result = { - check_tx: {}, - deliver_tx: {}, - txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', - height: 0, - logs: [], + tx_response: { + txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', + code: 0, + }, } const nodeUrl = thorClient.getClientUrl().node mockAccountsAddress(nodeUrl, testnet_address_path0, { - height: 0, - result: { - coins: [ - { - denom: 'rune', - amount: '210000000', - }, - ], + account: { + '@type': '/cosmos.auth.v1beta1.BaseAccount', + address: testnet_address_path0, + pub_key: { + '@type': '/cosmos.crypto.secp256k1.PubKey', + key: 'AyB84hKBjN2wsmdC2eF1Ppz6l3VxlfSKJpYsTaL4VrrE', + }, account_number: '0', sequence: '0', }, }) mockAccountsBalance(nodeUrl, testnet_address_path0, { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'rune', amount: '210000000', - }, + }), ], }) mockThorchainConstants(nodeUrl) - assertTxsPost(thorClient.getClientUrl().node, memo, expected_txsPost_result) + assertTxsPost(thorClient.getClientUrl().node, expected_txsPost_result) const result = await thorClient.transfer({ asset: AssetRuneNative, @@ -474,64 +488,34 @@ describe('Client Test', () => { const memo = 'swap:BNB.BNB:tbnb1ftzhmpzr4t8ta3etu4x7nwujf9jqckp3th2lh0' const expected_txsPost_result = { - check_tx: {}, - deliver_tx: {}, - txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', - height: 0, - logs: [], + tx_response: { + txhash: 'EA2FAC9E82290DCB9B1374B4C95D7C4DD8B9614A96FACD38031865EB1DBAE24D', + code: 0, + }, } const nodeUrl = thorClient.getClientUrl().node mockAccountsAddress(nodeUrl, testnet_address_path0, { - height: 0, - result: { - coins: [ - { - denom: 'rune', - amount: '210000000', - }, - ], + account: { + '@type': '/cosmos.auth.v1beta1.BaseAccount', + address: testnet_address_path0, + pub_key: { + '@type': '/cosmos.crypto.secp256k1.PubKey', + key: 'AyB84hKBjN2wsmdC2eF1Ppz6l3VxlfSKJpYsTaL4VrrE', + }, account_number: '0', sequence: '0', }, }) mockAccountsBalance(nodeUrl, testnet_address_path0, { - height: 0, - result: [ - { + balances: [ + new proto.cosmos.base.v1beta1.Coin({ denom: 'rune', amount: '210000000', - }, + }), ], }) - mockThorchainDeposit(nodeUrl, { - type: 'cosmos-sdk/StdTx', - value: { - msg: [ - { - type: 'thorchain/MsgDeposit', - value: { - coins: [ - { - asset: 'THOR.RUNE', - amount: '10000', - }, - ], - memo: 'swap:BNB.BNB:tbnb1ftzhmpzr4t8ta3etu4x7nwujf9jqckp3th2lh0', - signer: 'tthor19kacmmyuf2ysyvq3t9nrl9495l5cvktj5c4eh4', - }, - }, - ], - fee: { - amount: [], - gas: '100000000', - }, - signatures: [], - memo: '', - timeout_height: '0', - }, - }) mockTendermintNodeInfo(nodeUrl, { default_node_info: { network: chainIds[Network.Testnet], @@ -540,7 +524,7 @@ describe('Client Test', () => { mockThorchainConstants(nodeUrl) - assertTxsPost(nodeUrl, '', expected_txsPost_result) + assertTxsPost(nodeUrl, expected_txsPost_result) const result = await thorClient.deposit({ asset: AssetRuneNative, @@ -555,7 +539,7 @@ describe('Client Test', () => { const txData = require('../__mocks__/responses/txs/bond-tn-9C175AF7ACE9FCDC930B78909FFF598C18CBEAF9F39D7AA2C4D9A27BB7E55A5C.json') const txHash = '9C175AF7ACE9FCDC930B78909FFF598C18CBEAF9F39D7AA2C4D9A27BB7E55A5C' const address = 'tthor137kees65jmhjm3gxyune0km5ea0zkpnj4lw29f' - assertTxHashGet(thorClient.getClientUrl().node, txHash, txData) + assertTxHashGet(thorClient.getClientUrl().node, txHash, { tx_response: txData }) const { type, hash, asset, from, to } = await thorClient.getTransactionData(txHash, address) expect(type).toEqual('transfer') diff --git a/packages/xchain-thorchain/genMsgs.sh b/packages/xchain-thorchain/genMsgs.sh new file mode 100755 index 000000000..778282135 --- /dev/null +++ b/packages/xchain-thorchain/genMsgs.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# this script checks out thornode master and generates the proto3 typescript buindings for MsgDeposit and MsgSend + +MSG_COMPILED_OUTPUTFILE=src/types/proto/MsgCompiled.js +MSG_COMPILED_TYPES_OUTPUTFILE=src/types/proto/MsgCompiled.d.ts + + +TMP_DIR=$(mktemp -d) + +tput setaf 2; echo "Checking out https://gitlab.com/thorchain/thornode to $TMP_DIR";tput sgr0 +(cd $TMP_DIR && git clone https://gitlab.com/thorchain/thornode) + +# Generate msgs +tput setaf 2; echo "Generating $MSG_COMPILED_OUTPUTFILE";tput sgr0 +yarn run pbjs -w commonjs -t static-module $TMP_DIR/thornode/proto/thorchain/v1/common/common.proto $TMP_DIR/thornode/proto/thorchain/v1/x/thorchain/types/msg_deposit.proto $TMP_DIR/thornode/proto/thorchain/v1/x/thorchain/types/msg_send.proto $TMP_DIR/thornode/third_party/proto/cosmos/base/v1beta1/coin.proto -o $MSG_COMPILED_OUTPUTFILE + +tput setaf 2; echo "Generating $MSG_COMPILED_TYPES_OUTPUTFILE";tput sgr0 +yarn run pbts $MSG_COMPILED_OUTPUTFILE -o $MSG_COMPILED_TYPES_OUTPUTFILE + +tput setaf 2; echo "Removing $TMP_DIR/thornode";tput sgr0 +rm -rf $TMP_DIR diff --git a/packages/xchain-thorchain/jest.config.e2e.js b/packages/xchain-thorchain/jest.config.e2e.js new file mode 100644 index 000000000..c7e753cbd --- /dev/null +++ b/packages/xchain-thorchain/jest.config.e2e.js @@ -0,0 +1,7 @@ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', + testPathIgnorePatterns: ['/node_modules', '/lib'], + testMatch: ['/__e2e__/**/*.[jt]s?(x)'], + setupFilesAfterEnv: ['./jest.setup.js'], +} diff --git a/packages/xchain-thorchain/jest.config.js b/packages/xchain-thorchain/jest.config.js index 2c5daf952..26c1123fc 100644 --- a/packages/xchain-thorchain/jest.config.js +++ b/packages/xchain-thorchain/jest.config.js @@ -2,5 +2,5 @@ module.exports = { preset: 'ts-jest', testEnvironment: 'node', testPathIgnorePatterns: ['/node_modules', '/lib'], - setupFilesAfterEnv: ['./jest.setup.js'], + setupFilesAfterEnv: ['./jest.setup.js'] } diff --git a/packages/xchain-thorchain/jest.setup.js b/packages/xchain-thorchain/jest.setup.js index daa161e9b..7f0aeddaa 100644 --- a/packages/xchain-thorchain/jest.setup.js +++ b/packages/xchain-thorchain/jest.setup.js @@ -1 +1 @@ -jest.setTimeout(30000) +jest.setTimeout(60000) diff --git a/packages/xchain-thorchain/package.json b/packages/xchain-thorchain/package.json index 1ba545170..c45cd7a5a 100644 --- a/packages/xchain-thorchain/package.json +++ b/packages/xchain-thorchain/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-thorchain", - "version": "0.23.0", + "version": "0.24.0-alpha.1", "description": "Custom Thorchain client and utilities used by XChainJS clients", "keywords": [ "THORChain", @@ -27,29 +27,33 @@ "clean": "rimraf lib/**", "build": "yarn clean && rollup -c", "test": "jest", + "e2e": "jest --config jest.config.e2e.js", "lint": "eslint \"{src,__tests__}/**/*.ts\" --fix --max-warnings 0", "prepublishOnly": "yarn build", - "start:example": "ts-node example/index.ts" + "start:example": "ts-node example/index.ts", + "generate:ThorchainMsgs": "./genMsgs.sh" }, "devDependencies": { + "@cosmos-client/core": "^0.45.1", "@types/big.js": "^6.0.0", "@xchainjs/xchain-client": "^0.11.1", - "@xchainjs/xchain-cosmos": "^0.16.1", + "@xchainjs/xchain-cosmos": "^0.17.0-alpha.1", "@xchainjs/xchain-crypto": "^0.2.4", "@xchainjs/xchain-util": "^0.5.1", "axios": "^0.25.0", - "cosmos-client": "0.39.2", + "bech32-buffer": "^0.2.0", "nock": "^13.0.5" }, "publishConfig": { "access": "public" }, "peerDependencies": { + "@cosmos-client/core": "^0.45.1", "@xchainjs/xchain-client": "^0.11.1", - "@xchainjs/xchain-cosmos": "^0.16.1", + "@xchainjs/xchain-cosmos": "^0.17.0", "@xchainjs/xchain-crypto": "^0.2.4", "@xchainjs/xchain-util": "^0.5.1", "axios": "^0.25.0", - "cosmos-client": "0.39.2" + "bech32-buffer": "^0.2.0" } -} +} \ No newline at end of file diff --git a/packages/xchain-thorchain/src/client.ts b/packages/xchain-thorchain/src/client.ts index f30d494ad..363976259 100644 --- a/packages/xchain-thorchain/src/client.ts +++ b/packages/xchain-thorchain/src/client.ts @@ -1,10 +1,11 @@ +import { cosmosclient, proto } from '@cosmos-client/core' import { Address, Balance, + BaseXChainClient, FeeType, Fees, Network, - RootDerivationPaths, Tx, TxFrom, TxHash, @@ -18,12 +19,18 @@ import { singleFee, } from '@xchainjs/xchain-client' import { CosmosSDKClient, RPCTxResult } from '@xchainjs/xchain-cosmos' -import * as xchainCrypto from '@xchainjs/xchain-crypto' -import { Asset, AssetRuneNative, BaseAmount, assetFromString, assetToString, baseAmount } from '@xchainjs/xchain-util' +import { + Asset, + AssetRuneNative, + BaseAmount, + Chain, + assetFromString, + assetToString, + baseAmount, +} from '@xchainjs/xchain-util' import axios from 'axios' -import { AccAddress, PrivKey, PubKey, codec } from 'cosmos-client' -import { StdTx } from 'cosmos-client/x/auth' +import { buildDepositTx, buildTransferTx, buildUnsignedTx } from '.' import { ChainId, ChainIds, @@ -36,12 +43,12 @@ import { TxData, TxOfflineParams, } from './types' -import { TxResult, msgNativeTxFromJson } from './types/messages' +import { TxResult } from './types/messages' import { DECIMAL, DEFAULT_GAS_VALUE, + DEPOSIT_GAS_VALUE, MAX_TX_COUNT, - buildDepositTx, getBalance, getDefaultClientUrl, getDefaultExplorerUrls, @@ -52,8 +59,8 @@ import { getExplorerTxUrl, getPrefix, isAssetRuneNative, - isBroadcastSuccess, - registerCodecs, + registerDespositCodecs, + registerSendCodecs, } from './util' /** @@ -71,13 +78,10 @@ export interface ThorchainClient { /** * Custom Thorchain Client */ -class Client implements ThorchainClient, XChainClient { - private network: Network +class Client extends BaseXChainClient implements ThorchainClient, XChainClient { private clientUrl: ClientUrl private explorerUrls: ExplorerUrls private chainIds: ChainIds - private phrase = '' - private rootDerivationPaths: RootDerivationPaths private cosmosClient: CosmosSDKClient /** @@ -102,28 +106,16 @@ class Client implements ThorchainClient, XChainClient { }, chainIds, }: XChainClientParams & ThorchainClientParams) { - this.network = network + super(Chain.Cosmos, { network, rootDerivationPaths, phrase }) this.clientUrl = clientUrl || getDefaultClientUrl() this.explorerUrls = explorerUrls || getDefaultExplorerUrls() this.chainIds = chainIds - this.rootDerivationPaths = rootDerivationPaths this.cosmosClient = new CosmosSDKClient({ server: this.getClientUrl().node, - chainId: this.getChainId(this.network), - prefix: getPrefix(this.network), + chainId: this.getChainId(network), + prefix: getPrefix(network), }) - - if (phrase) this.setPhrase(phrase) - } - - /** - * Purge client. - * - * @returns {void} - */ - purgeClient(): void { - this.phrase = '' } /** @@ -136,23 +128,10 @@ class Client implements ThorchainClient, XChainClient { * Thrown if network has not been set before. */ setNetwork(network: Network): void { - if (!network) { - throw new Error('Network must be provided') - } - - this.network = network + super.setNetwork(network) this.cosmosClient.updatePrefix(getPrefix(this.network)) } - /** - * Get the current network. - * - * @returns {Network} - */ - getNetwork(): Network { - return this.network - } - /** * Set/update the client URL. * @@ -242,36 +221,6 @@ class Client implements ThorchainClient, XChainClient { return getExplorerTxUrl({ urls: this.explorerUrls, network: this.network, txID }) } - /** - * Set/update a new phrase - * - * @param {string} phrase A new phrase. - * @returns {Address} The address from the given phrase - * - * @throws {"Invalid phrase"} - * Thrown if the given phase is invalid. - */ - setPhrase(phrase: string, walletIndex = 0): Address { - if (this.phrase !== phrase) { - if (!xchainCrypto.validatePhrase(phrase)) { - throw new Error('Invalid phrase') - } - this.phrase = phrase - } - - return this.getAddress(walletIndex) - } - - /** - * Get getFullDerivationPath - * - * @param {number} index the HD wallet index - * @returns {string} The bitcoin derivation path based on the network. - */ - getFullDerivationPath(index: number): string { - return this.rootDerivationPaths[this.network] + `${index}` - } - /** * Get private key * @@ -281,7 +230,7 @@ class Client implements ThorchainClient, XChainClient { * @throws {"Phrase not set"} * Throws an error if phrase has not been set before * */ - getPrivKey(index = 0): PrivKey { + getPrivateKey(index = 0): proto.cosmos.crypto.secp256k1.PrivKey { return this.cosmosClient.getPrivKeyFromMnemonic(this.phrase, this.getFullDerivationPath(index)) } @@ -295,8 +244,9 @@ class Client implements ThorchainClient, XChainClient { * @throws {"Phrase not set"} * Throws an error if phrase has not been set before **/ - getPubKey(index = 0): PubKey { - return this.getPrivKey(index).getPubKey() + getPubKey(index = 0): cosmosclient.PubKey { + const privKey = this.getPrivateKey(index) + return privKey.pubKey() } /** @@ -353,8 +303,6 @@ class Client implements ThorchainClient, XChainClient { const txMinHeight = undefined const txMaxHeight = undefined - registerCodecs(getPrefix(this.network)) - const txIncomingHistory = ( await this.cosmosClient.searchTxFromRPC({ rpcEndpoint: this.getClientUrl().rpc, @@ -376,7 +324,8 @@ class Client implements ThorchainClient, XChainClient { }) ).txs - let history: RPCTxResult[] = [...txIncomingHistory, ...txOutgoingHistory] + let history: RPCTxResult[] = txIncomingHistory + .concat(txOutgoingHistory) .sort((a, b) => { if (a.height !== b.height) return parseInt(b.height) > parseInt(a.height) ? 1 : -1 if (a.hash !== b.hash) return a.hash > b.hash ? 1 : -1 @@ -410,8 +359,8 @@ class Client implements ThorchainClient, XChainClient { */ async getTransactionData(txId: string, address: Address): Promise { const txResult = await this.cosmosClient.txsHashGet(txId) - const txData: TxData | null = txResult.logs ? getDepositTxDataFromLogs(txResult.logs, address) : null - if (!txData) throw new Error(`Failed to get transaction data (tx-hash: ${txId})`) + const txData: TxData | null = txResult && txResult.logs ? getDepositTxDataFromLogs(txResult.logs, address) : null + if (!txResult || !txData) throw new Error(`Failed to get transaction data (tx-hash: ${txId})`) const { from, to, type } = txData @@ -472,6 +421,7 @@ class Client implements ThorchainClient, XChainClient { * @throws {"failed to broadcast transaction"} Thrown if failed to broadcast transaction. */ async deposit({ walletIndex = 0, asset = AssetRuneNative, amount, memo }: DepositParam): Promise { + await registerDespositCodecs() const balances = await this.getBalance(this.getAddress(walletIndex)) const runeBalance: BaseAmount = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]?.amount ?? baseAmount(0, DECIMAL) @@ -493,27 +443,38 @@ class Client implements ThorchainClient, XChainClient { } } - const signer = this.getAddress(walletIndex) - const msgNativeTx = msgNativeTxFromJson({ - coins: [ - { - asset: isAssetRuneNative(asset) ? assetToString(AssetRuneNative) : getDenom(asset), - amount: amount.amount().toString(), - }, - ], - memo, - signer, - }) - - const unsignedStdTx: StdTx = await buildDepositTx({ - msgNativeTx, + const privKey = this.getPrivateKey(walletIndex) + const signerPubkey = privKey.pubKey() + + const fromAddress = this.getAddress(walletIndex) + const fromAddressAcc = cosmosclient.AccAddress.fromString(fromAddress) + + const depositTxBody = await buildDepositTx({ + msgNativeTx: { + memo: memo, + signer: fromAddressAcc, + coins: [ + { + asset: asset, + amount: amount.amount().toString(), + }, + ], + }, nodeUrl: this.getClientUrl().node, chainId: this.getChainId(), }) - const privateKey = this.getPrivKey(walletIndex) - const accAddress = AccAddress.fromBech32(signer) - return (await this.cosmosClient.signAndBroadcast(unsignedStdTx, privateKey, accAddress))?.txhash ?? '' + const account = await this.getCosmosClient().getAccount(fromAddressAcc) + + const txBuilder = buildUnsignedTx({ + cosmosSdk: this.getCosmosClient().sdk, + txBody: depositTxBody, + signerPubkey: cosmosclient.codec.packAny(signerPubkey), + gasLimit: DEPOSIT_GAS_VALUE, + sequence: account.sequence || cosmosclient.Long.ZERO, + }) + + return (await this.getCosmosClient().signAndBroadcast(txBuilder, privKey, account)) || '' } /** @@ -523,8 +484,7 @@ class Client implements ThorchainClient, XChainClient { * @returns {TxHash} The transaction hash. */ async transfer({ walletIndex = 0, asset = AssetRuneNative, amount, recipient, memo }: TxParams): Promise { - registerCodecs(getPrefix(this.network)) - + await registerSendCodecs() const balances = await this.getBalance(this.getAddress(walletIndex)) const runeBalance: BaseAmount = balances.filter(({ asset }) => isAssetRuneNative(asset))[0]?.amount ?? baseAmount(0, DECIMAL) @@ -545,32 +505,41 @@ class Client implements ThorchainClient, XChainClient { throw new Error('insufficient funds') } } - - const transferResult = await this.cosmosClient.transfer({ - privkey: this.getPrivKey(walletIndex), - from: this.getAddress(walletIndex), - to: recipient, - amount: amount.amount().toString(), - asset: getDenom(asset), - memo, - fee: { - amount: [], - gas: DEFAULT_GAS_VALUE, - }, + const privKey = this.getPrivateKey(walletIndex) + const from = this.getAddress(walletIndex) + const signerPubkey = privKey.pubKey() + const accAddress = cosmosclient.AccAddress.fromString(from) + + const denom = getDenom(asset) + + const txBody = await buildTransferTx({ + fromAddress: from, + toAddress: recipient, + memo: memo, + assetAmount: amount, + assetDenom: denom, + chainId: this.getChainId(), + nodeUrl: this.getClientUrl().node, }) - if (!isBroadcastSuccess(transferResult)) { - throw new Error(`failed to broadcast transaction: ${transferResult.txhash}`) - } + const account = await this.getCosmosClient().getAccount(accAddress) - return transferResult?.txhash || '' + const txBuilder = buildUnsignedTx({ + cosmosSdk: this.getCosmosClient().sdk, + txBody: txBody, + gasLimit: DEFAULT_GAS_VALUE, + signerPubkey: cosmosclient.codec.packAny(signerPubkey), + sequence: account.sequence || cosmosclient.Long.ZERO, + }) + + return (await this.cosmosClient.signAndBroadcast(txBuilder, privKey, account)) || '' } /** * Transfer without broadcast balances with MsgSend * * @param {TxOfflineParams} params The transfer offline options. - * @returns {StdTx} The signed transaction. + * @returns {string} The signed transaction bytes. */ async transferOffline({ walletIndex = 0, @@ -582,9 +551,7 @@ class Client implements ThorchainClient, XChainClient { from_asset_balance = baseAmount(0, DECIMAL), from_account_number = '0', from_sequence = '0', - }: TxOfflineParams): Promise { - registerCodecs(getPrefix(this.network)) - + }: TxOfflineParams): Promise { const fee = (await this.getFees()).average if (isAssetRuneNative(asset)) { @@ -599,22 +566,29 @@ class Client implements ThorchainClient, XChainClient { } } - const result = await this.cosmosClient.transferSignedOffline({ - privkey: this.getPrivKey(walletIndex), - from: this.getAddress(walletIndex), - from_account_number, - from_sequence, - to: recipient, - amount: amount.amount().toString(), - asset: getDenom(asset), + const txBody = await buildTransferTx({ + fromAddress: this.getAddress(walletIndex), + toAddress: recipient, memo, - fee: { - amount: [], - gas: DEFAULT_GAS_VALUE, - }, + assetAmount: amount, + assetDenom: getDenom(asset), + chainId: this.getChainId(), + nodeUrl: this.getClientUrl().node, + }) + + const privKey = this.getPrivateKey(walletIndex) + + const txBuilder = buildUnsignedTx({ + cosmosSdk: this.getCosmosClient().sdk, + txBody: txBody, + gasLimit: DEFAULT_GAS_VALUE, + signerPubkey: cosmosclient.codec.packAny(privKey.pubKey()), + sequence: cosmosclient.Long.fromString(from_sequence) || cosmosclient.Long.ZERO, }) - return JSON.parse(codec.toJSONString(result)).value + const signDocBytes = txBuilder.signDocBytes(cosmosclient.Long.fromString(from_account_number)) + txBuilder.addSignature(privKey.sign(signDocBytes)) + return txBuilder.txBytes() } /** diff --git a/packages/xchain-thorchain/src/types/messages.ts b/packages/xchain-thorchain/src/types/messages.ts index 57d438842..aa3968e78 100644 --- a/packages/xchain-thorchain/src/types/messages.ts +++ b/packages/xchain-thorchain/src/types/messages.ts @@ -1,20 +1,17 @@ -import { AccAddress, Msg } from 'cosmos-client' -import { StdTxFee } from 'cosmos-client/api' -import { StdSignature } from 'cosmos-client/x/auth' +import { cosmosclient, proto } from '@cosmos-client/core' +import { Asset } from '@xchainjs/xchain-util' export type MsgCoin = { - asset: string + asset: Asset amount: string } -export class MsgNativeTx extends Msg { +export class MsgNativeTx { coins: MsgCoin[] memo: string - signer: AccAddress - - constructor(coins: MsgCoin[], memo: string, signer: AccAddress) { - super() + signer: cosmosclient.AccAddress + constructor(coins: MsgCoin[], memo: string, signer: cosmosclient.AccAddress) { this.coins = coins this.memo = memo this.signer = signer @@ -28,7 +25,7 @@ export class MsgNativeTx extends Msg { * @returns {MsgNativeTx} */ export const msgNativeTxFromJson = (value: { coins: MsgCoin[]; memo: string; signer: string }): MsgNativeTx => { - return new MsgNativeTx(value.coins, value.memo, AccAddress.fromBech32(value.signer)) + return new MsgNativeTx(value.coins, value.memo, cosmosclient.AccAddress.fromString(value.signer)) } export type AminoWrapping = { @@ -42,8 +39,8 @@ export type ThorchainDepositResponse = AminoWrapping<{ memo: string signer: string }>[] - fee: StdTxFee - signatures: StdSignature[] + fee: proto.cosmos.tx.v1beta1.Fee + signatures: string[] memo: string timeout_height: string }> diff --git a/packages/xchain-thorchain/src/types/proto/MsgCompiled.d.ts b/packages/xchain-thorchain/src/types/proto/MsgCompiled.d.ts new file mode 100644 index 000000000..d20261a0e --- /dev/null +++ b/packages/xchain-thorchain/src/types/proto/MsgCompiled.d.ts @@ -0,0 +1,1118 @@ +import * as $protobuf from 'protobufjs' +/** Namespace common. */ +export namespace common { + /** Properties of an Asset. */ + interface IAsset { + /** Asset chain */ + chain?: string | null + + /** Asset symbol */ + symbol?: string | null + + /** Asset ticker */ + ticker?: string | null + + /** Asset synth */ + synth?: boolean | null + } + + /** Represents an Asset. */ + class Asset implements IAsset { + /** + * Constructs a new Asset. + * @param [properties] Properties to set + */ + constructor(properties?: common.IAsset) + + /** Asset chain. */ + public chain: string + + /** Asset symbol. */ + public symbol: string + + /** Asset ticker. */ + public ticker: string + + /** Asset synth. */ + public synth: boolean + + /** + * Creates a new Asset instance using the specified properties. + * @param [properties] Properties to set + * @returns Asset instance + */ + public static create(properties?: common.IAsset): common.Asset + + /** + * Encodes the specified Asset message. Does not implicitly {@link common.Asset.verify|verify} messages. + * @param message Asset message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: common.IAsset, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified Asset message, length delimited. Does not implicitly {@link common.Asset.verify|verify} messages. + * @param message Asset message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: common.IAsset, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes an Asset message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Asset + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): common.Asset + + /** + * Decodes an Asset message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Asset + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): common.Asset + + /** + * Verifies an Asset message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates an Asset message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Asset + */ + public static fromObject(object: { [k: string]: any }): common.Asset + + /** + * Creates a plain object from an Asset message. Also converts values to other types if specified. + * @param message Asset + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: common.Asset, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this Asset to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a Coin. */ + interface ICoin { + /** Coin asset */ + asset?: common.IAsset | null + + /** Coin amount */ + amount?: string | null + + /** Coin decimals */ + decimals?: number | Long | null + } + + /** Represents a Coin. */ + class Coin implements ICoin { + /** + * Constructs a new Coin. + * @param [properties] Properties to set + */ + constructor(properties?: common.ICoin) + + /** Coin asset. */ + public asset?: common.IAsset | null + + /** Coin amount. */ + public amount: string + + /** Coin decimals. */ + public decimals: number | Long + + /** + * Creates a new Coin instance using the specified properties. + * @param [properties] Properties to set + * @returns Coin instance + */ + public static create(properties?: common.ICoin): common.Coin + + /** + * Encodes the specified Coin message. Does not implicitly {@link common.Coin.verify|verify} messages. + * @param message Coin message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: common.ICoin, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified Coin message, length delimited. Does not implicitly {@link common.Coin.verify|verify} messages. + * @param message Coin message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: common.ICoin, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a Coin message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): common.Coin + + /** + * Decodes a Coin message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): common.Coin + + /** + * Verifies a Coin message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a Coin message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Coin + */ + public static fromObject(object: { [k: string]: any }): common.Coin + + /** + * Creates a plain object from a Coin message. Also converts values to other types if specified. + * @param message Coin + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: common.Coin, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this Coin to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a PubKeySet. */ + interface IPubKeySet { + /** PubKeySet secp256k1 */ + secp256k1?: string | null + + /** PubKeySet ed25519 */ + ed25519?: string | null + } + + /** Represents a PubKeySet. */ + class PubKeySet implements IPubKeySet { + /** + * Constructs a new PubKeySet. + * @param [properties] Properties to set + */ + constructor(properties?: common.IPubKeySet) + + /** PubKeySet secp256k1. */ + public secp256k1: string + + /** PubKeySet ed25519. */ + public ed25519: string + + /** + * Creates a new PubKeySet instance using the specified properties. + * @param [properties] Properties to set + * @returns PubKeySet instance + */ + public static create(properties?: common.IPubKeySet): common.PubKeySet + + /** + * Encodes the specified PubKeySet message. Does not implicitly {@link common.PubKeySet.verify|verify} messages. + * @param message PubKeySet message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: common.IPubKeySet, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified PubKeySet message, length delimited. Does not implicitly {@link common.PubKeySet.verify|verify} messages. + * @param message PubKeySet message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: common.IPubKeySet, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a PubKeySet message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns PubKeySet + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): common.PubKeySet + + /** + * Decodes a PubKeySet message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns PubKeySet + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): common.PubKeySet + + /** + * Verifies a PubKeySet message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a PubKeySet message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns PubKeySet + */ + public static fromObject(object: { [k: string]: any }): common.PubKeySet + + /** + * Creates a plain object from a PubKeySet message. Also converts values to other types if specified. + * @param message PubKeySet + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: common.PubKeySet, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this PubKeySet to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a Tx. */ + interface ITx { + /** Tx id */ + id?: string | null + + /** Tx chain */ + chain?: string | null + + /** Tx fromAddress */ + fromAddress?: string | null + + /** Tx toAddress */ + toAddress?: string | null + + /** Tx coins */ + coins?: common.ICoin[] | null + + /** Tx gas */ + gas?: common.ICoin[] | null + + /** Tx memo */ + memo?: string | null + } + + /** Represents a Tx. */ + class Tx implements ITx { + /** + * Constructs a new Tx. + * @param [properties] Properties to set + */ + constructor(properties?: common.ITx) + + /** Tx id. */ + public id: string + + /** Tx chain. */ + public chain: string + + /** Tx fromAddress. */ + public fromAddress: string + + /** Tx toAddress. */ + public toAddress: string + + /** Tx coins. */ + public coins: common.ICoin[] + + /** Tx gas. */ + public gas: common.ICoin[] + + /** Tx memo. */ + public memo: string + + /** + * Creates a new Tx instance using the specified properties. + * @param [properties] Properties to set + * @returns Tx instance + */ + public static create(properties?: common.ITx): common.Tx + + /** + * Encodes the specified Tx message. Does not implicitly {@link common.Tx.verify|verify} messages. + * @param message Tx message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: common.ITx, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified Tx message, length delimited. Does not implicitly {@link common.Tx.verify|verify} messages. + * @param message Tx message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: common.ITx, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a Tx message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Tx + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): common.Tx + + /** + * Decodes a Tx message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Tx + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): common.Tx + + /** + * Verifies a Tx message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a Tx message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Tx + */ + public static fromObject(object: { [k: string]: any }): common.Tx + + /** + * Creates a plain object from a Tx message. Also converts values to other types if specified. + * @param message Tx + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: common.Tx, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this Tx to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a Fee. */ + interface IFee { + /** Fee coins */ + coins?: common.ICoin[] | null + + /** Fee poolDeduct */ + poolDeduct?: string | null + } + + /** Represents a Fee. */ + class Fee implements IFee { + /** + * Constructs a new Fee. + * @param [properties] Properties to set + */ + constructor(properties?: common.IFee) + + /** Fee coins. */ + public coins: common.ICoin[] + + /** Fee poolDeduct. */ + public poolDeduct: string + + /** + * Creates a new Fee instance using the specified properties. + * @param [properties] Properties to set + * @returns Fee instance + */ + public static create(properties?: common.IFee): common.Fee + + /** + * Encodes the specified Fee message. Does not implicitly {@link common.Fee.verify|verify} messages. + * @param message Fee message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: common.IFee, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified Fee message, length delimited. Does not implicitly {@link common.Fee.verify|verify} messages. + * @param message Fee message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: common.IFee, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a Fee message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Fee + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): common.Fee + + /** + * Decodes a Fee message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Fee + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): common.Fee + + /** + * Verifies a Fee message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a Fee message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Fee + */ + public static fromObject(object: { [k: string]: any }): common.Fee + + /** + * Creates a plain object from a Fee message. Also converts values to other types if specified. + * @param message Fee + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: common.Fee, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this Fee to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } +} + +/** Namespace types. */ +export namespace types { + /** Properties of a MsgDeposit. */ + interface IMsgDeposit { + /** MsgDeposit coins */ + coins?: common.ICoin[] | null + + /** MsgDeposit memo */ + memo?: string | null + + /** MsgDeposit signer */ + signer?: Uint8Array | null + } + + /** Represents a MsgDeposit. */ + class MsgDeposit implements IMsgDeposit { + /** + * Constructs a new MsgDeposit. + * @param [properties] Properties to set + */ + constructor(properties?: types.IMsgDeposit) + + /** MsgDeposit coins. */ + public coins: common.ICoin[] + + /** MsgDeposit memo. */ + public memo: string + + /** MsgDeposit signer. */ + public signer: Uint8Array + + /** + * Creates a new MsgDeposit instance using the specified properties. + * @param [properties] Properties to set + * @returns MsgDeposit instance + */ + public static create(properties?: types.IMsgDeposit): types.MsgDeposit + + /** + * Encodes the specified MsgDeposit message. Does not implicitly {@link types.MsgDeposit.verify|verify} messages. + * @param message MsgDeposit message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: types.IMsgDeposit, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified MsgDeposit message, length delimited. Does not implicitly {@link types.MsgDeposit.verify|verify} messages. + * @param message MsgDeposit message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: types.IMsgDeposit, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a MsgDeposit message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns MsgDeposit + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): types.MsgDeposit + + /** + * Decodes a MsgDeposit message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns MsgDeposit + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): types.MsgDeposit + + /** + * Verifies a MsgDeposit message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a MsgDeposit message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns MsgDeposit + */ + public static fromObject(object: { [k: string]: any }): types.MsgDeposit + + /** + * Creates a plain object from a MsgDeposit message. Also converts values to other types if specified. + * @param message MsgDeposit + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: types.MsgDeposit, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this MsgDeposit to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a MsgSend. */ + interface IMsgSend { + /** MsgSend fromAddress */ + fromAddress?: Uint8Array | null + + /** MsgSend toAddress */ + toAddress?: Uint8Array | null + + /** MsgSend amount */ + amount?: cosmos.base.v1beta1.ICoin[] | null + } + + /** Represents a MsgSend. */ + class MsgSend implements IMsgSend { + /** + * Constructs a new MsgSend. + * @param [properties] Properties to set + */ + constructor(properties?: types.IMsgSend) + + /** MsgSend fromAddress. */ + public fromAddress: Uint8Array + + /** MsgSend toAddress. */ + public toAddress: Uint8Array + + /** MsgSend amount. */ + public amount: cosmos.base.v1beta1.ICoin[] + + /** + * Creates a new MsgSend instance using the specified properties. + * @param [properties] Properties to set + * @returns MsgSend instance + */ + public static create(properties?: types.IMsgSend): types.MsgSend + + /** + * Encodes the specified MsgSend message. Does not implicitly {@link types.MsgSend.verify|verify} messages. + * @param message MsgSend message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: types.IMsgSend, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified MsgSend message, length delimited. Does not implicitly {@link types.MsgSend.verify|verify} messages. + * @param message MsgSend message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: types.IMsgSend, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a MsgSend message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns MsgSend + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): types.MsgSend + + /** + * Decodes a MsgSend message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns MsgSend + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): types.MsgSend + + /** + * Verifies a MsgSend message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a MsgSend message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns MsgSend + */ + public static fromObject(object: { [k: string]: any }): types.MsgSend + + /** + * Creates a plain object from a MsgSend message. Also converts values to other types if specified. + * @param message MsgSend + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject(message: types.MsgSend, options?: $protobuf.IConversionOptions): { [k: string]: any } + + /** + * Converts this MsgSend to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } +} + +/** Namespace cosmos. */ +export namespace cosmos { + /** Namespace base. */ + namespace base { + /** Namespace v1beta1. */ + namespace v1beta1 { + /** Properties of a Coin. */ + interface ICoin { + /** Coin denom */ + denom?: string | null + + /** Coin amount */ + amount?: string | null + } + + /** Represents a Coin. */ + class Coin implements ICoin { + /** + * Constructs a new Coin. + * @param [properties] Properties to set + */ + constructor(properties?: cosmos.base.v1beta1.ICoin) + + /** Coin denom. */ + public denom: string + + /** Coin amount. */ + public amount: string + + /** + * Creates a new Coin instance using the specified properties. + * @param [properties] Properties to set + * @returns Coin instance + */ + public static create(properties?: cosmos.base.v1beta1.ICoin): cosmos.base.v1beta1.Coin + + /** + * Encodes the specified Coin message. Does not implicitly {@link cosmos.base.v1beta1.Coin.verify|verify} messages. + * @param message Coin message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: cosmos.base.v1beta1.ICoin, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified Coin message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.Coin.verify|verify} messages. + * @param message Coin message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited(message: cosmos.base.v1beta1.ICoin, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Decodes a Coin message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): cosmos.base.v1beta1.Coin + + /** + * Decodes a Coin message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): cosmos.base.v1beta1.Coin + + /** + * Verifies a Coin message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a Coin message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns Coin + */ + public static fromObject(object: { [k: string]: any }): cosmos.base.v1beta1.Coin + + /** + * Creates a plain object from a Coin message. Also converts values to other types if specified. + * @param message Coin + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject( + message: cosmos.base.v1beta1.Coin, + options?: $protobuf.IConversionOptions, + ): { [k: string]: any } + + /** + * Converts this Coin to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a DecCoin. */ + interface IDecCoin { + /** DecCoin denom */ + denom?: string | null + + /** DecCoin amount */ + amount?: string | null + } + + /** Represents a DecCoin. */ + class DecCoin implements IDecCoin { + /** + * Constructs a new DecCoin. + * @param [properties] Properties to set + */ + constructor(properties?: cosmos.base.v1beta1.IDecCoin) + + /** DecCoin denom. */ + public denom: string + + /** DecCoin amount. */ + public amount: string + + /** + * Creates a new DecCoin instance using the specified properties. + * @param [properties] Properties to set + * @returns DecCoin instance + */ + public static create(properties?: cosmos.base.v1beta1.IDecCoin): cosmos.base.v1beta1.DecCoin + + /** + * Encodes the specified DecCoin message. Does not implicitly {@link cosmos.base.v1beta1.DecCoin.verify|verify} messages. + * @param message DecCoin message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: cosmos.base.v1beta1.IDecCoin, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified DecCoin message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.DecCoin.verify|verify} messages. + * @param message DecCoin message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited( + message: cosmos.base.v1beta1.IDecCoin, + writer?: $protobuf.Writer, + ): $protobuf.Writer + + /** + * Decodes a DecCoin message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns DecCoin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): cosmos.base.v1beta1.DecCoin + + /** + * Decodes a DecCoin message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns DecCoin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): cosmos.base.v1beta1.DecCoin + + /** + * Verifies a DecCoin message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a DecCoin message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns DecCoin + */ + public static fromObject(object: { [k: string]: any }): cosmos.base.v1beta1.DecCoin + + /** + * Creates a plain object from a DecCoin message. Also converts values to other types if specified. + * @param message DecCoin + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject( + message: cosmos.base.v1beta1.DecCoin, + options?: $protobuf.IConversionOptions, + ): { [k: string]: any } + + /** + * Converts this DecCoin to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of an IntProto. */ + interface IIntProto { + /** IntProto int */ + int?: string | null + } + + /** Represents an IntProto. */ + class IntProto implements IIntProto { + /** + * Constructs a new IntProto. + * @param [properties] Properties to set + */ + constructor(properties?: cosmos.base.v1beta1.IIntProto) + + /** IntProto int. */ + public int: string + + /** + * Creates a new IntProto instance using the specified properties. + * @param [properties] Properties to set + * @returns IntProto instance + */ + public static create(properties?: cosmos.base.v1beta1.IIntProto): cosmos.base.v1beta1.IntProto + + /** + * Encodes the specified IntProto message. Does not implicitly {@link cosmos.base.v1beta1.IntProto.verify|verify} messages. + * @param message IntProto message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: cosmos.base.v1beta1.IIntProto, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified IntProto message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.IntProto.verify|verify} messages. + * @param message IntProto message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited( + message: cosmos.base.v1beta1.IIntProto, + writer?: $protobuf.Writer, + ): $protobuf.Writer + + /** + * Decodes an IntProto message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns IntProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): cosmos.base.v1beta1.IntProto + + /** + * Decodes an IntProto message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns IntProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): cosmos.base.v1beta1.IntProto + + /** + * Verifies an IntProto message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates an IntProto message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns IntProto + */ + public static fromObject(object: { [k: string]: any }): cosmos.base.v1beta1.IntProto + + /** + * Creates a plain object from an IntProto message. Also converts values to other types if specified. + * @param message IntProto + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject( + message: cosmos.base.v1beta1.IntProto, + options?: $protobuf.IConversionOptions, + ): { [k: string]: any } + + /** + * Converts this IntProto to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + + /** Properties of a DecProto. */ + interface IDecProto { + /** DecProto dec */ + dec?: string | null + } + + /** Represents a DecProto. */ + class DecProto implements IDecProto { + /** + * Constructs a new DecProto. + * @param [properties] Properties to set + */ + constructor(properties?: cosmos.base.v1beta1.IDecProto) + + /** DecProto dec. */ + public dec: string + + /** + * Creates a new DecProto instance using the specified properties. + * @param [properties] Properties to set + * @returns DecProto instance + */ + public static create(properties?: cosmos.base.v1beta1.IDecProto): cosmos.base.v1beta1.DecProto + + /** + * Encodes the specified DecProto message. Does not implicitly {@link cosmos.base.v1beta1.DecProto.verify|verify} messages. + * @param message DecProto message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encode(message: cosmos.base.v1beta1.IDecProto, writer?: $protobuf.Writer): $protobuf.Writer + + /** + * Encodes the specified DecProto message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.DecProto.verify|verify} messages. + * @param message DecProto message or plain object to encode + * @param [writer] Writer to encode to + * @returns Writer + */ + public static encodeDelimited( + message: cosmos.base.v1beta1.IDecProto, + writer?: $protobuf.Writer, + ): $protobuf.Writer + + /** + * Decodes a DecProto message from the specified reader or buffer. + * @param reader Reader or buffer to decode from + * @param [length] Message length if known beforehand + * @returns DecProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decode(reader: $protobuf.Reader | Uint8Array, length?: number): cosmos.base.v1beta1.DecProto + + /** + * Decodes a DecProto message from the specified reader or buffer, length delimited. + * @param reader Reader or buffer to decode from + * @returns DecProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + public static decodeDelimited(reader: $protobuf.Reader | Uint8Array): cosmos.base.v1beta1.DecProto + + /** + * Verifies a DecProto message. + * @param message Plain object to verify + * @returns `null` if valid, otherwise the reason why it is not + */ + public static verify(message: { [k: string]: any }): string | null + + /** + * Creates a DecProto message from a plain object. Also converts values to their respective internal types. + * @param object Plain object + * @returns DecProto + */ + public static fromObject(object: { [k: string]: any }): cosmos.base.v1beta1.DecProto + + /** + * Creates a plain object from a DecProto message. Also converts values to other types if specified. + * @param message DecProto + * @param [options] Conversion options + * @returns Plain object + */ + public static toObject( + message: cosmos.base.v1beta1.DecProto, + options?: $protobuf.IConversionOptions, + ): { [k: string]: any } + + /** + * Converts this DecProto to JSON. + * @returns JSON object + */ + public toJSON(): { [k: string]: any } + } + } + } +} diff --git a/packages/xchain-thorchain/src/types/proto/MsgCompiled.js b/packages/xchain-thorchain/src/types/proto/MsgCompiled.js new file mode 100644 index 000000000..3443064ef --- /dev/null +++ b/packages/xchain-thorchain/src/types/proto/MsgCompiled.js @@ -0,0 +1,2711 @@ +/*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/ +"use strict"; + +var $protobuf = require("protobufjs/minimal"); + +// Common aliases +var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; + +// Exported root namespace +var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); + +$root.common = (function() { + + /** + * Namespace common. + * @exports common + * @namespace + */ + var common = {}; + + common.Asset = (function() { + + /** + * Properties of an Asset. + * @memberof common + * @interface IAsset + * @property {string|null} [chain] Asset chain + * @property {string|null} [symbol] Asset symbol + * @property {string|null} [ticker] Asset ticker + * @property {boolean|null} [synth] Asset synth + */ + + /** + * Constructs a new Asset. + * @memberof common + * @classdesc Represents an Asset. + * @implements IAsset + * @constructor + * @param {common.IAsset=} [properties] Properties to set + */ + function Asset(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Asset chain. + * @member {string} chain + * @memberof common.Asset + * @instance + */ + Asset.prototype.chain = ""; + + /** + * Asset symbol. + * @member {string} symbol + * @memberof common.Asset + * @instance + */ + Asset.prototype.symbol = ""; + + /** + * Asset ticker. + * @member {string} ticker + * @memberof common.Asset + * @instance + */ + Asset.prototype.ticker = ""; + + /** + * Asset synth. + * @member {boolean} synth + * @memberof common.Asset + * @instance + */ + Asset.prototype.synth = false; + + /** + * Creates a new Asset instance using the specified properties. + * @function create + * @memberof common.Asset + * @static + * @param {common.IAsset=} [properties] Properties to set + * @returns {common.Asset} Asset instance + */ + Asset.create = function create(properties) { + return new Asset(properties); + }; + + /** + * Encodes the specified Asset message. Does not implicitly {@link common.Asset.verify|verify} messages. + * @function encode + * @memberof common.Asset + * @static + * @param {common.IAsset} message Asset message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Asset.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.chain != null && Object.hasOwnProperty.call(message, "chain")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.chain); + if (message.symbol != null && Object.hasOwnProperty.call(message, "symbol")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.symbol); + if (message.ticker != null && Object.hasOwnProperty.call(message, "ticker")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.ticker); + if (message.synth != null && Object.hasOwnProperty.call(message, "synth")) + writer.uint32(/* id 4, wireType 0 =*/32).bool(message.synth); + return writer; + }; + + /** + * Encodes the specified Asset message, length delimited. Does not implicitly {@link common.Asset.verify|verify} messages. + * @function encodeDelimited + * @memberof common.Asset + * @static + * @param {common.IAsset} message Asset message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Asset.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an Asset message from the specified reader or buffer. + * @function decode + * @memberof common.Asset + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {common.Asset} Asset + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Asset.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Asset(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.chain = reader.string(); + break; + case 2: + message.symbol = reader.string(); + break; + case 3: + message.ticker = reader.string(); + break; + case 4: + message.synth = reader.bool(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an Asset message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof common.Asset + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {common.Asset} Asset + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Asset.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an Asset message. + * @function verify + * @memberof common.Asset + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Asset.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.chain != null && message.hasOwnProperty("chain")) + if (!$util.isString(message.chain)) + return "chain: string expected"; + if (message.symbol != null && message.hasOwnProperty("symbol")) + if (!$util.isString(message.symbol)) + return "symbol: string expected"; + if (message.ticker != null && message.hasOwnProperty("ticker")) + if (!$util.isString(message.ticker)) + return "ticker: string expected"; + if (message.synth != null && message.hasOwnProperty("synth")) + if (typeof message.synth !== "boolean") + return "synth: boolean expected"; + return null; + }; + + /** + * Creates an Asset message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof common.Asset + * @static + * @param {Object.} object Plain object + * @returns {common.Asset} Asset + */ + Asset.fromObject = function fromObject(object) { + if (object instanceof $root.common.Asset) + return object; + var message = new $root.common.Asset(); + if (object.chain != null) + message.chain = String(object.chain); + if (object.symbol != null) + message.symbol = String(object.symbol); + if (object.ticker != null) + message.ticker = String(object.ticker); + if (object.synth != null) + message.synth = Boolean(object.synth); + return message; + }; + + /** + * Creates a plain object from an Asset message. Also converts values to other types if specified. + * @function toObject + * @memberof common.Asset + * @static + * @param {common.Asset} message Asset + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Asset.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.chain = ""; + object.symbol = ""; + object.ticker = ""; + object.synth = false; + } + if (message.chain != null && message.hasOwnProperty("chain")) + object.chain = message.chain; + if (message.symbol != null && message.hasOwnProperty("symbol")) + object.symbol = message.symbol; + if (message.ticker != null && message.hasOwnProperty("ticker")) + object.ticker = message.ticker; + if (message.synth != null && message.hasOwnProperty("synth")) + object.synth = message.synth; + return object; + }; + + /** + * Converts this Asset to JSON. + * @function toJSON + * @memberof common.Asset + * @instance + * @returns {Object.} JSON object + */ + Asset.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Asset; + })(); + + common.Coin = (function() { + + /** + * Properties of a Coin. + * @memberof common + * @interface ICoin + * @property {common.IAsset|null} [asset] Coin asset + * @property {string|null} [amount] Coin amount + * @property {number|Long|null} [decimals] Coin decimals + */ + + /** + * Constructs a new Coin. + * @memberof common + * @classdesc Represents a Coin. + * @implements ICoin + * @constructor + * @param {common.ICoin=} [properties] Properties to set + */ + function Coin(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Coin asset. + * @member {common.IAsset|null|undefined} asset + * @memberof common.Coin + * @instance + */ + Coin.prototype.asset = null; + + /** + * Coin amount. + * @member {string} amount + * @memberof common.Coin + * @instance + */ + Coin.prototype.amount = ""; + + /** + * Coin decimals. + * @member {number|Long} decimals + * @memberof common.Coin + * @instance + */ + Coin.prototype.decimals = $util.Long ? $util.Long.fromBits(0,0,false) : 0; + + /** + * Creates a new Coin instance using the specified properties. + * @function create + * @memberof common.Coin + * @static + * @param {common.ICoin=} [properties] Properties to set + * @returns {common.Coin} Coin instance + */ + Coin.create = function create(properties) { + return new Coin(properties); + }; + + /** + * Encodes the specified Coin message. Does not implicitly {@link common.Coin.verify|verify} messages. + * @function encode + * @memberof common.Coin + * @static + * @param {common.ICoin} message Coin message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Coin.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.asset != null && Object.hasOwnProperty.call(message, "asset")) + $root.common.Asset.encode(message.asset, writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.amount != null && Object.hasOwnProperty.call(message, "amount")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.amount); + if (message.decimals != null && Object.hasOwnProperty.call(message, "decimals")) + writer.uint32(/* id 3, wireType 0 =*/24).int64(message.decimals); + return writer; + }; + + /** + * Encodes the specified Coin message, length delimited. Does not implicitly {@link common.Coin.verify|verify} messages. + * @function encodeDelimited + * @memberof common.Coin + * @static + * @param {common.ICoin} message Coin message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Coin.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Coin message from the specified reader or buffer. + * @function decode + * @memberof common.Coin + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {common.Coin} Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Coin.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Coin(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.asset = $root.common.Asset.decode(reader, reader.uint32()); + break; + case 2: + message.amount = reader.string(); + break; + case 3: + message.decimals = reader.int64(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Coin message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof common.Coin + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {common.Coin} Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Coin.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Coin message. + * @function verify + * @memberof common.Coin + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Coin.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.asset != null && message.hasOwnProperty("asset")) { + var error = $root.common.Asset.verify(message.asset); + if (error) + return "asset." + error; + } + if (message.amount != null && message.hasOwnProperty("amount")) + if (!$util.isString(message.amount)) + return "amount: string expected"; + if (message.decimals != null && message.hasOwnProperty("decimals")) + if (!$util.isInteger(message.decimals) && !(message.decimals && $util.isInteger(message.decimals.low) && $util.isInteger(message.decimals.high))) + return "decimals: integer|Long expected"; + return null; + }; + + /** + * Creates a Coin message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof common.Coin + * @static + * @param {Object.} object Plain object + * @returns {common.Coin} Coin + */ + Coin.fromObject = function fromObject(object) { + if (object instanceof $root.common.Coin) + return object; + var message = new $root.common.Coin(); + if (object.asset != null) { + if (typeof object.asset !== "object") + throw TypeError(".common.Coin.asset: object expected"); + message.asset = $root.common.Asset.fromObject(object.asset); + } + if (object.amount != null) + message.amount = String(object.amount); + if (object.decimals != null) + if ($util.Long) + (message.decimals = $util.Long.fromValue(object.decimals)).unsigned = false; + else if (typeof object.decimals === "string") + message.decimals = parseInt(object.decimals, 10); + else if (typeof object.decimals === "number") + message.decimals = object.decimals; + else if (typeof object.decimals === "object") + message.decimals = new $util.LongBits(object.decimals.low >>> 0, object.decimals.high >>> 0).toNumber(); + return message; + }; + + /** + * Creates a plain object from a Coin message. Also converts values to other types if specified. + * @function toObject + * @memberof common.Coin + * @static + * @param {common.Coin} message Coin + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Coin.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.asset = null; + object.amount = ""; + if ($util.Long) { + var long = new $util.Long(0, 0, false); + object.decimals = options.longs === String ? long.toString() : options.longs === Number ? long.toNumber() : long; + } else + object.decimals = options.longs === String ? "0" : 0; + } + if (message.asset != null && message.hasOwnProperty("asset")) + object.asset = $root.common.Asset.toObject(message.asset, options); + if (message.amount != null && message.hasOwnProperty("amount")) + object.amount = message.amount; + if (message.decimals != null && message.hasOwnProperty("decimals")) + if (typeof message.decimals === "number") + object.decimals = options.longs === String ? String(message.decimals) : message.decimals; + else + object.decimals = options.longs === String ? $util.Long.prototype.toString.call(message.decimals) : options.longs === Number ? new $util.LongBits(message.decimals.low >>> 0, message.decimals.high >>> 0).toNumber() : message.decimals; + return object; + }; + + /** + * Converts this Coin to JSON. + * @function toJSON + * @memberof common.Coin + * @instance + * @returns {Object.} JSON object + */ + Coin.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Coin; + })(); + + common.PubKeySet = (function() { + + /** + * Properties of a PubKeySet. + * @memberof common + * @interface IPubKeySet + * @property {string|null} [secp256k1] PubKeySet secp256k1 + * @property {string|null} [ed25519] PubKeySet ed25519 + */ + + /** + * Constructs a new PubKeySet. + * @memberof common + * @classdesc Represents a PubKeySet. + * @implements IPubKeySet + * @constructor + * @param {common.IPubKeySet=} [properties] Properties to set + */ + function PubKeySet(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * PubKeySet secp256k1. + * @member {string} secp256k1 + * @memberof common.PubKeySet + * @instance + */ + PubKeySet.prototype.secp256k1 = ""; + + /** + * PubKeySet ed25519. + * @member {string} ed25519 + * @memberof common.PubKeySet + * @instance + */ + PubKeySet.prototype.ed25519 = ""; + + /** + * Creates a new PubKeySet instance using the specified properties. + * @function create + * @memberof common.PubKeySet + * @static + * @param {common.IPubKeySet=} [properties] Properties to set + * @returns {common.PubKeySet} PubKeySet instance + */ + PubKeySet.create = function create(properties) { + return new PubKeySet(properties); + }; + + /** + * Encodes the specified PubKeySet message. Does not implicitly {@link common.PubKeySet.verify|verify} messages. + * @function encode + * @memberof common.PubKeySet + * @static + * @param {common.IPubKeySet} message PubKeySet message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + PubKeySet.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.secp256k1 != null && Object.hasOwnProperty.call(message, "secp256k1")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.secp256k1); + if (message.ed25519 != null && Object.hasOwnProperty.call(message, "ed25519")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.ed25519); + return writer; + }; + + /** + * Encodes the specified PubKeySet message, length delimited. Does not implicitly {@link common.PubKeySet.verify|verify} messages. + * @function encodeDelimited + * @memberof common.PubKeySet + * @static + * @param {common.IPubKeySet} message PubKeySet message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + PubKeySet.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a PubKeySet message from the specified reader or buffer. + * @function decode + * @memberof common.PubKeySet + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {common.PubKeySet} PubKeySet + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + PubKeySet.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.PubKeySet(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.secp256k1 = reader.string(); + break; + case 2: + message.ed25519 = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a PubKeySet message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof common.PubKeySet + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {common.PubKeySet} PubKeySet + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + PubKeySet.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a PubKeySet message. + * @function verify + * @memberof common.PubKeySet + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + PubKeySet.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.secp256k1 != null && message.hasOwnProperty("secp256k1")) + if (!$util.isString(message.secp256k1)) + return "secp256k1: string expected"; + if (message.ed25519 != null && message.hasOwnProperty("ed25519")) + if (!$util.isString(message.ed25519)) + return "ed25519: string expected"; + return null; + }; + + /** + * Creates a PubKeySet message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof common.PubKeySet + * @static + * @param {Object.} object Plain object + * @returns {common.PubKeySet} PubKeySet + */ + PubKeySet.fromObject = function fromObject(object) { + if (object instanceof $root.common.PubKeySet) + return object; + var message = new $root.common.PubKeySet(); + if (object.secp256k1 != null) + message.secp256k1 = String(object.secp256k1); + if (object.ed25519 != null) + message.ed25519 = String(object.ed25519); + return message; + }; + + /** + * Creates a plain object from a PubKeySet message. Also converts values to other types if specified. + * @function toObject + * @memberof common.PubKeySet + * @static + * @param {common.PubKeySet} message PubKeySet + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + PubKeySet.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.secp256k1 = ""; + object.ed25519 = ""; + } + if (message.secp256k1 != null && message.hasOwnProperty("secp256k1")) + object.secp256k1 = message.secp256k1; + if (message.ed25519 != null && message.hasOwnProperty("ed25519")) + object.ed25519 = message.ed25519; + return object; + }; + + /** + * Converts this PubKeySet to JSON. + * @function toJSON + * @memberof common.PubKeySet + * @instance + * @returns {Object.} JSON object + */ + PubKeySet.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return PubKeySet; + })(); + + common.Tx = (function() { + + /** + * Properties of a Tx. + * @memberof common + * @interface ITx + * @property {string|null} [id] Tx id + * @property {string|null} [chain] Tx chain + * @property {string|null} [fromAddress] Tx fromAddress + * @property {string|null} [toAddress] Tx toAddress + * @property {Array.|null} [coins] Tx coins + * @property {Array.|null} [gas] Tx gas + * @property {string|null} [memo] Tx memo + */ + + /** + * Constructs a new Tx. + * @memberof common + * @classdesc Represents a Tx. + * @implements ITx + * @constructor + * @param {common.ITx=} [properties] Properties to set + */ + function Tx(properties) { + this.coins = []; + this.gas = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Tx id. + * @member {string} id + * @memberof common.Tx + * @instance + */ + Tx.prototype.id = ""; + + /** + * Tx chain. + * @member {string} chain + * @memberof common.Tx + * @instance + */ + Tx.prototype.chain = ""; + + /** + * Tx fromAddress. + * @member {string} fromAddress + * @memberof common.Tx + * @instance + */ + Tx.prototype.fromAddress = ""; + + /** + * Tx toAddress. + * @member {string} toAddress + * @memberof common.Tx + * @instance + */ + Tx.prototype.toAddress = ""; + + /** + * Tx coins. + * @member {Array.} coins + * @memberof common.Tx + * @instance + */ + Tx.prototype.coins = $util.emptyArray; + + /** + * Tx gas. + * @member {Array.} gas + * @memberof common.Tx + * @instance + */ + Tx.prototype.gas = $util.emptyArray; + + /** + * Tx memo. + * @member {string} memo + * @memberof common.Tx + * @instance + */ + Tx.prototype.memo = ""; + + /** + * Creates a new Tx instance using the specified properties. + * @function create + * @memberof common.Tx + * @static + * @param {common.ITx=} [properties] Properties to set + * @returns {common.Tx} Tx instance + */ + Tx.create = function create(properties) { + return new Tx(properties); + }; + + /** + * Encodes the specified Tx message. Does not implicitly {@link common.Tx.verify|verify} messages. + * @function encode + * @memberof common.Tx + * @static + * @param {common.ITx} message Tx message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Tx.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.id != null && Object.hasOwnProperty.call(message, "id")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.id); + if (message.chain != null && Object.hasOwnProperty.call(message, "chain")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.chain); + if (message.fromAddress != null && Object.hasOwnProperty.call(message, "fromAddress")) + writer.uint32(/* id 3, wireType 2 =*/26).string(message.fromAddress); + if (message.toAddress != null && Object.hasOwnProperty.call(message, "toAddress")) + writer.uint32(/* id 4, wireType 2 =*/34).string(message.toAddress); + if (message.coins != null && message.coins.length) + for (var i = 0; i < message.coins.length; ++i) + $root.common.Coin.encode(message.coins[i], writer.uint32(/* id 5, wireType 2 =*/42).fork()).ldelim(); + if (message.gas != null && message.gas.length) + for (var i = 0; i < message.gas.length; ++i) + $root.common.Coin.encode(message.gas[i], writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim(); + if (message.memo != null && Object.hasOwnProperty.call(message, "memo")) + writer.uint32(/* id 7, wireType 2 =*/58).string(message.memo); + return writer; + }; + + /** + * Encodes the specified Tx message, length delimited. Does not implicitly {@link common.Tx.verify|verify} messages. + * @function encodeDelimited + * @memberof common.Tx + * @static + * @param {common.ITx} message Tx message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Tx.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Tx message from the specified reader or buffer. + * @function decode + * @memberof common.Tx + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {common.Tx} Tx + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Tx.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Tx(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.id = reader.string(); + break; + case 2: + message.chain = reader.string(); + break; + case 3: + message.fromAddress = reader.string(); + break; + case 4: + message.toAddress = reader.string(); + break; + case 5: + if (!(message.coins && message.coins.length)) + message.coins = []; + message.coins.push($root.common.Coin.decode(reader, reader.uint32())); + break; + case 6: + if (!(message.gas && message.gas.length)) + message.gas = []; + message.gas.push($root.common.Coin.decode(reader, reader.uint32())); + break; + case 7: + message.memo = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Tx message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof common.Tx + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {common.Tx} Tx + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Tx.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Tx message. + * @function verify + * @memberof common.Tx + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Tx.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.id != null && message.hasOwnProperty("id")) + if (!$util.isString(message.id)) + return "id: string expected"; + if (message.chain != null && message.hasOwnProperty("chain")) + if (!$util.isString(message.chain)) + return "chain: string expected"; + if (message.fromAddress != null && message.hasOwnProperty("fromAddress")) + if (!$util.isString(message.fromAddress)) + return "fromAddress: string expected"; + if (message.toAddress != null && message.hasOwnProperty("toAddress")) + if (!$util.isString(message.toAddress)) + return "toAddress: string expected"; + if (message.coins != null && message.hasOwnProperty("coins")) { + if (!Array.isArray(message.coins)) + return "coins: array expected"; + for (var i = 0; i < message.coins.length; ++i) { + var error = $root.common.Coin.verify(message.coins[i]); + if (error) + return "coins." + error; + } + } + if (message.gas != null && message.hasOwnProperty("gas")) { + if (!Array.isArray(message.gas)) + return "gas: array expected"; + for (var i = 0; i < message.gas.length; ++i) { + var error = $root.common.Coin.verify(message.gas[i]); + if (error) + return "gas." + error; + } + } + if (message.memo != null && message.hasOwnProperty("memo")) + if (!$util.isString(message.memo)) + return "memo: string expected"; + return null; + }; + + /** + * Creates a Tx message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof common.Tx + * @static + * @param {Object.} object Plain object + * @returns {common.Tx} Tx + */ + Tx.fromObject = function fromObject(object) { + if (object instanceof $root.common.Tx) + return object; + var message = new $root.common.Tx(); + if (object.id != null) + message.id = String(object.id); + if (object.chain != null) + message.chain = String(object.chain); + if (object.fromAddress != null) + message.fromAddress = String(object.fromAddress); + if (object.toAddress != null) + message.toAddress = String(object.toAddress); + if (object.coins) { + if (!Array.isArray(object.coins)) + throw TypeError(".common.Tx.coins: array expected"); + message.coins = []; + for (var i = 0; i < object.coins.length; ++i) { + if (typeof object.coins[i] !== "object") + throw TypeError(".common.Tx.coins: object expected"); + message.coins[i] = $root.common.Coin.fromObject(object.coins[i]); + } + } + if (object.gas) { + if (!Array.isArray(object.gas)) + throw TypeError(".common.Tx.gas: array expected"); + message.gas = []; + for (var i = 0; i < object.gas.length; ++i) { + if (typeof object.gas[i] !== "object") + throw TypeError(".common.Tx.gas: object expected"); + message.gas[i] = $root.common.Coin.fromObject(object.gas[i]); + } + } + if (object.memo != null) + message.memo = String(object.memo); + return message; + }; + + /** + * Creates a plain object from a Tx message. Also converts values to other types if specified. + * @function toObject + * @memberof common.Tx + * @static + * @param {common.Tx} message Tx + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Tx.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) { + object.coins = []; + object.gas = []; + } + if (options.defaults) { + object.id = ""; + object.chain = ""; + object.fromAddress = ""; + object.toAddress = ""; + object.memo = ""; + } + if (message.id != null && message.hasOwnProperty("id")) + object.id = message.id; + if (message.chain != null && message.hasOwnProperty("chain")) + object.chain = message.chain; + if (message.fromAddress != null && message.hasOwnProperty("fromAddress")) + object.fromAddress = message.fromAddress; + if (message.toAddress != null && message.hasOwnProperty("toAddress")) + object.toAddress = message.toAddress; + if (message.coins && message.coins.length) { + object.coins = []; + for (var j = 0; j < message.coins.length; ++j) + object.coins[j] = $root.common.Coin.toObject(message.coins[j], options); + } + if (message.gas && message.gas.length) { + object.gas = []; + for (var j = 0; j < message.gas.length; ++j) + object.gas[j] = $root.common.Coin.toObject(message.gas[j], options); + } + if (message.memo != null && message.hasOwnProperty("memo")) + object.memo = message.memo; + return object; + }; + + /** + * Converts this Tx to JSON. + * @function toJSON + * @memberof common.Tx + * @instance + * @returns {Object.} JSON object + */ + Tx.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Tx; + })(); + + common.Fee = (function() { + + /** + * Properties of a Fee. + * @memberof common + * @interface IFee + * @property {Array.|null} [coins] Fee coins + * @property {string|null} [poolDeduct] Fee poolDeduct + */ + + /** + * Constructs a new Fee. + * @memberof common + * @classdesc Represents a Fee. + * @implements IFee + * @constructor + * @param {common.IFee=} [properties] Properties to set + */ + function Fee(properties) { + this.coins = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Fee coins. + * @member {Array.} coins + * @memberof common.Fee + * @instance + */ + Fee.prototype.coins = $util.emptyArray; + + /** + * Fee poolDeduct. + * @member {string} poolDeduct + * @memberof common.Fee + * @instance + */ + Fee.prototype.poolDeduct = ""; + + /** + * Creates a new Fee instance using the specified properties. + * @function create + * @memberof common.Fee + * @static + * @param {common.IFee=} [properties] Properties to set + * @returns {common.Fee} Fee instance + */ + Fee.create = function create(properties) { + return new Fee(properties); + }; + + /** + * Encodes the specified Fee message. Does not implicitly {@link common.Fee.verify|verify} messages. + * @function encode + * @memberof common.Fee + * @static + * @param {common.IFee} message Fee message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Fee.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.coins != null && message.coins.length) + for (var i = 0; i < message.coins.length; ++i) + $root.common.Coin.encode(message.coins[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.poolDeduct != null && Object.hasOwnProperty.call(message, "poolDeduct")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.poolDeduct); + return writer; + }; + + /** + * Encodes the specified Fee message, length delimited. Does not implicitly {@link common.Fee.verify|verify} messages. + * @function encodeDelimited + * @memberof common.Fee + * @static + * @param {common.IFee} message Fee message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Fee.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Fee message from the specified reader or buffer. + * @function decode + * @memberof common.Fee + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {common.Fee} Fee + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Fee.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.common.Fee(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.coins && message.coins.length)) + message.coins = []; + message.coins.push($root.common.Coin.decode(reader, reader.uint32())); + break; + case 2: + message.poolDeduct = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Fee message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof common.Fee + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {common.Fee} Fee + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Fee.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Fee message. + * @function verify + * @memberof common.Fee + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Fee.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.coins != null && message.hasOwnProperty("coins")) { + if (!Array.isArray(message.coins)) + return "coins: array expected"; + for (var i = 0; i < message.coins.length; ++i) { + var error = $root.common.Coin.verify(message.coins[i]); + if (error) + return "coins." + error; + } + } + if (message.poolDeduct != null && message.hasOwnProperty("poolDeduct")) + if (!$util.isString(message.poolDeduct)) + return "poolDeduct: string expected"; + return null; + }; + + /** + * Creates a Fee message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof common.Fee + * @static + * @param {Object.} object Plain object + * @returns {common.Fee} Fee + */ + Fee.fromObject = function fromObject(object) { + if (object instanceof $root.common.Fee) + return object; + var message = new $root.common.Fee(); + if (object.coins) { + if (!Array.isArray(object.coins)) + throw TypeError(".common.Fee.coins: array expected"); + message.coins = []; + for (var i = 0; i < object.coins.length; ++i) { + if (typeof object.coins[i] !== "object") + throw TypeError(".common.Fee.coins: object expected"); + message.coins[i] = $root.common.Coin.fromObject(object.coins[i]); + } + } + if (object.poolDeduct != null) + message.poolDeduct = String(object.poolDeduct); + return message; + }; + + /** + * Creates a plain object from a Fee message. Also converts values to other types if specified. + * @function toObject + * @memberof common.Fee + * @static + * @param {common.Fee} message Fee + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Fee.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.coins = []; + if (options.defaults) + object.poolDeduct = ""; + if (message.coins && message.coins.length) { + object.coins = []; + for (var j = 0; j < message.coins.length; ++j) + object.coins[j] = $root.common.Coin.toObject(message.coins[j], options); + } + if (message.poolDeduct != null && message.hasOwnProperty("poolDeduct")) + object.poolDeduct = message.poolDeduct; + return object; + }; + + /** + * Converts this Fee to JSON. + * @function toJSON + * @memberof common.Fee + * @instance + * @returns {Object.} JSON object + */ + Fee.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Fee; + })(); + + return common; +})(); + +$root.types = (function() { + + /** + * Namespace types. + * @exports types + * @namespace + */ + var types = {}; + + types.MsgDeposit = (function() { + + /** + * Properties of a MsgDeposit. + * @memberof types + * @interface IMsgDeposit + * @property {Array.|null} [coins] MsgDeposit coins + * @property {string|null} [memo] MsgDeposit memo + * @property {Uint8Array|null} [signer] MsgDeposit signer + */ + + /** + * Constructs a new MsgDeposit. + * @memberof types + * @classdesc Represents a MsgDeposit. + * @implements IMsgDeposit + * @constructor + * @param {types.IMsgDeposit=} [properties] Properties to set + */ + function MsgDeposit(properties) { + this.coins = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * MsgDeposit coins. + * @member {Array.} coins + * @memberof types.MsgDeposit + * @instance + */ + MsgDeposit.prototype.coins = $util.emptyArray; + + /** + * MsgDeposit memo. + * @member {string} memo + * @memberof types.MsgDeposit + * @instance + */ + MsgDeposit.prototype.memo = ""; + + /** + * MsgDeposit signer. + * @member {Uint8Array} signer + * @memberof types.MsgDeposit + * @instance + */ + MsgDeposit.prototype.signer = $util.newBuffer([]); + + /** + * Creates a new MsgDeposit instance using the specified properties. + * @function create + * @memberof types.MsgDeposit + * @static + * @param {types.IMsgDeposit=} [properties] Properties to set + * @returns {types.MsgDeposit} MsgDeposit instance + */ + MsgDeposit.create = function create(properties) { + return new MsgDeposit(properties); + }; + + /** + * Encodes the specified MsgDeposit message. Does not implicitly {@link types.MsgDeposit.verify|verify} messages. + * @function encode + * @memberof types.MsgDeposit + * @static + * @param {types.IMsgDeposit} message MsgDeposit message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + MsgDeposit.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.coins != null && message.coins.length) + for (var i = 0; i < message.coins.length; ++i) + $root.common.Coin.encode(message.coins[i], writer.uint32(/* id 1, wireType 2 =*/10).fork()).ldelim(); + if (message.memo != null && Object.hasOwnProperty.call(message, "memo")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.memo); + if (message.signer != null && Object.hasOwnProperty.call(message, "signer")) + writer.uint32(/* id 3, wireType 2 =*/26).bytes(message.signer); + return writer; + }; + + /** + * Encodes the specified MsgDeposit message, length delimited. Does not implicitly {@link types.MsgDeposit.verify|verify} messages. + * @function encodeDelimited + * @memberof types.MsgDeposit + * @static + * @param {types.IMsgDeposit} message MsgDeposit message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + MsgDeposit.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a MsgDeposit message from the specified reader or buffer. + * @function decode + * @memberof types.MsgDeposit + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {types.MsgDeposit} MsgDeposit + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + MsgDeposit.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.types.MsgDeposit(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + if (!(message.coins && message.coins.length)) + message.coins = []; + message.coins.push($root.common.Coin.decode(reader, reader.uint32())); + break; + case 2: + message.memo = reader.string(); + break; + case 3: + message.signer = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a MsgDeposit message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof types.MsgDeposit + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {types.MsgDeposit} MsgDeposit + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + MsgDeposit.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a MsgDeposit message. + * @function verify + * @memberof types.MsgDeposit + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + MsgDeposit.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.coins != null && message.hasOwnProperty("coins")) { + if (!Array.isArray(message.coins)) + return "coins: array expected"; + for (var i = 0; i < message.coins.length; ++i) { + var error = $root.common.Coin.verify(message.coins[i]); + if (error) + return "coins." + error; + } + } + if (message.memo != null && message.hasOwnProperty("memo")) + if (!$util.isString(message.memo)) + return "memo: string expected"; + if (message.signer != null && message.hasOwnProperty("signer")) + if (!(message.signer && typeof message.signer.length === "number" || $util.isString(message.signer))) + return "signer: buffer expected"; + return null; + }; + + /** + * Creates a MsgDeposit message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof types.MsgDeposit + * @static + * @param {Object.} object Plain object + * @returns {types.MsgDeposit} MsgDeposit + */ + MsgDeposit.fromObject = function fromObject(object) { + if (object instanceof $root.types.MsgDeposit) + return object; + var message = new $root.types.MsgDeposit(); + if (object.coins) { + if (!Array.isArray(object.coins)) + throw TypeError(".types.MsgDeposit.coins: array expected"); + message.coins = []; + for (var i = 0; i < object.coins.length; ++i) { + if (typeof object.coins[i] !== "object") + throw TypeError(".types.MsgDeposit.coins: object expected"); + message.coins[i] = $root.common.Coin.fromObject(object.coins[i]); + } + } + if (object.memo != null) + message.memo = String(object.memo); + if (object.signer != null) + if (typeof object.signer === "string") + $util.base64.decode(object.signer, message.signer = $util.newBuffer($util.base64.length(object.signer)), 0); + else if (object.signer.length) + message.signer = object.signer; + return message; + }; + + /** + * Creates a plain object from a MsgDeposit message. Also converts values to other types if specified. + * @function toObject + * @memberof types.MsgDeposit + * @static + * @param {types.MsgDeposit} message MsgDeposit + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + MsgDeposit.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.coins = []; + if (options.defaults) { + object.memo = ""; + if (options.bytes === String) + object.signer = ""; + else { + object.signer = []; + if (options.bytes !== Array) + object.signer = $util.newBuffer(object.signer); + } + } + if (message.coins && message.coins.length) { + object.coins = []; + for (var j = 0; j < message.coins.length; ++j) + object.coins[j] = $root.common.Coin.toObject(message.coins[j], options); + } + if (message.memo != null && message.hasOwnProperty("memo")) + object.memo = message.memo; + if (message.signer != null && message.hasOwnProperty("signer")) + object.signer = options.bytes === String ? $util.base64.encode(message.signer, 0, message.signer.length) : options.bytes === Array ? Array.prototype.slice.call(message.signer) : message.signer; + return object; + }; + + /** + * Converts this MsgDeposit to JSON. + * @function toJSON + * @memberof types.MsgDeposit + * @instance + * @returns {Object.} JSON object + */ + MsgDeposit.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return MsgDeposit; + })(); + + types.MsgSend = (function() { + + /** + * Properties of a MsgSend. + * @memberof types + * @interface IMsgSend + * @property {Uint8Array|null} [fromAddress] MsgSend fromAddress + * @property {Uint8Array|null} [toAddress] MsgSend toAddress + * @property {Array.|null} [amount] MsgSend amount + */ + + /** + * Constructs a new MsgSend. + * @memberof types + * @classdesc Represents a MsgSend. + * @implements IMsgSend + * @constructor + * @param {types.IMsgSend=} [properties] Properties to set + */ + function MsgSend(properties) { + this.amount = []; + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * MsgSend fromAddress. + * @member {Uint8Array} fromAddress + * @memberof types.MsgSend + * @instance + */ + MsgSend.prototype.fromAddress = $util.newBuffer([]); + + /** + * MsgSend toAddress. + * @member {Uint8Array} toAddress + * @memberof types.MsgSend + * @instance + */ + MsgSend.prototype.toAddress = $util.newBuffer([]); + + /** + * MsgSend amount. + * @member {Array.} amount + * @memberof types.MsgSend + * @instance + */ + MsgSend.prototype.amount = $util.emptyArray; + + /** + * Creates a new MsgSend instance using the specified properties. + * @function create + * @memberof types.MsgSend + * @static + * @param {types.IMsgSend=} [properties] Properties to set + * @returns {types.MsgSend} MsgSend instance + */ + MsgSend.create = function create(properties) { + return new MsgSend(properties); + }; + + /** + * Encodes the specified MsgSend message. Does not implicitly {@link types.MsgSend.verify|verify} messages. + * @function encode + * @memberof types.MsgSend + * @static + * @param {types.IMsgSend} message MsgSend message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + MsgSend.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.fromAddress != null && Object.hasOwnProperty.call(message, "fromAddress")) + writer.uint32(/* id 1, wireType 2 =*/10).bytes(message.fromAddress); + if (message.toAddress != null && Object.hasOwnProperty.call(message, "toAddress")) + writer.uint32(/* id 2, wireType 2 =*/18).bytes(message.toAddress); + if (message.amount != null && message.amount.length) + for (var i = 0; i < message.amount.length; ++i) + $root.cosmos.base.v1beta1.Coin.encode(message.amount[i], writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); + return writer; + }; + + /** + * Encodes the specified MsgSend message, length delimited. Does not implicitly {@link types.MsgSend.verify|verify} messages. + * @function encodeDelimited + * @memberof types.MsgSend + * @static + * @param {types.IMsgSend} message MsgSend message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + MsgSend.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a MsgSend message from the specified reader or buffer. + * @function decode + * @memberof types.MsgSend + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {types.MsgSend} MsgSend + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + MsgSend.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.types.MsgSend(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.fromAddress = reader.bytes(); + break; + case 2: + message.toAddress = reader.bytes(); + break; + case 3: + if (!(message.amount && message.amount.length)) + message.amount = []; + message.amount.push($root.cosmos.base.v1beta1.Coin.decode(reader, reader.uint32())); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a MsgSend message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof types.MsgSend + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {types.MsgSend} MsgSend + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + MsgSend.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a MsgSend message. + * @function verify + * @memberof types.MsgSend + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + MsgSend.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.fromAddress != null && message.hasOwnProperty("fromAddress")) + if (!(message.fromAddress && typeof message.fromAddress.length === "number" || $util.isString(message.fromAddress))) + return "fromAddress: buffer expected"; + if (message.toAddress != null && message.hasOwnProperty("toAddress")) + if (!(message.toAddress && typeof message.toAddress.length === "number" || $util.isString(message.toAddress))) + return "toAddress: buffer expected"; + if (message.amount != null && message.hasOwnProperty("amount")) { + if (!Array.isArray(message.amount)) + return "amount: array expected"; + for (var i = 0; i < message.amount.length; ++i) { + var error = $root.cosmos.base.v1beta1.Coin.verify(message.amount[i]); + if (error) + return "amount." + error; + } + } + return null; + }; + + /** + * Creates a MsgSend message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof types.MsgSend + * @static + * @param {Object.} object Plain object + * @returns {types.MsgSend} MsgSend + */ + MsgSend.fromObject = function fromObject(object) { + if (object instanceof $root.types.MsgSend) + return object; + var message = new $root.types.MsgSend(); + if (object.fromAddress != null) + if (typeof object.fromAddress === "string") + $util.base64.decode(object.fromAddress, message.fromAddress = $util.newBuffer($util.base64.length(object.fromAddress)), 0); + else if (object.fromAddress.length) + message.fromAddress = object.fromAddress; + if (object.toAddress != null) + if (typeof object.toAddress === "string") + $util.base64.decode(object.toAddress, message.toAddress = $util.newBuffer($util.base64.length(object.toAddress)), 0); + else if (object.toAddress.length) + message.toAddress = object.toAddress; + if (object.amount) { + if (!Array.isArray(object.amount)) + throw TypeError(".types.MsgSend.amount: array expected"); + message.amount = []; + for (var i = 0; i < object.amount.length; ++i) { + if (typeof object.amount[i] !== "object") + throw TypeError(".types.MsgSend.amount: object expected"); + message.amount[i] = $root.cosmos.base.v1beta1.Coin.fromObject(object.amount[i]); + } + } + return message; + }; + + /** + * Creates a plain object from a MsgSend message. Also converts values to other types if specified. + * @function toObject + * @memberof types.MsgSend + * @static + * @param {types.MsgSend} message MsgSend + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + MsgSend.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.arrays || options.defaults) + object.amount = []; + if (options.defaults) { + if (options.bytes === String) + object.fromAddress = ""; + else { + object.fromAddress = []; + if (options.bytes !== Array) + object.fromAddress = $util.newBuffer(object.fromAddress); + } + if (options.bytes === String) + object.toAddress = ""; + else { + object.toAddress = []; + if (options.bytes !== Array) + object.toAddress = $util.newBuffer(object.toAddress); + } + } + if (message.fromAddress != null && message.hasOwnProperty("fromAddress")) + object.fromAddress = options.bytes === String ? $util.base64.encode(message.fromAddress, 0, message.fromAddress.length) : options.bytes === Array ? Array.prototype.slice.call(message.fromAddress) : message.fromAddress; + if (message.toAddress != null && message.hasOwnProperty("toAddress")) + object.toAddress = options.bytes === String ? $util.base64.encode(message.toAddress, 0, message.toAddress.length) : options.bytes === Array ? Array.prototype.slice.call(message.toAddress) : message.toAddress; + if (message.amount && message.amount.length) { + object.amount = []; + for (var j = 0; j < message.amount.length; ++j) + object.amount[j] = $root.cosmos.base.v1beta1.Coin.toObject(message.amount[j], options); + } + return object; + }; + + /** + * Converts this MsgSend to JSON. + * @function toJSON + * @memberof types.MsgSend + * @instance + * @returns {Object.} JSON object + */ + MsgSend.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return MsgSend; + })(); + + return types; +})(); + +$root.cosmos = (function() { + + /** + * Namespace cosmos. + * @exports cosmos + * @namespace + */ + var cosmos = {}; + + cosmos.base = (function() { + + /** + * Namespace base. + * @memberof cosmos + * @namespace + */ + var base = {}; + + base.v1beta1 = (function() { + + /** + * Namespace v1beta1. + * @memberof cosmos.base + * @namespace + */ + var v1beta1 = {}; + + v1beta1.Coin = (function() { + + /** + * Properties of a Coin. + * @memberof cosmos.base.v1beta1 + * @interface ICoin + * @property {string|null} [denom] Coin denom + * @property {string|null} [amount] Coin amount + */ + + /** + * Constructs a new Coin. + * @memberof cosmos.base.v1beta1 + * @classdesc Represents a Coin. + * @implements ICoin + * @constructor + * @param {cosmos.base.v1beta1.ICoin=} [properties] Properties to set + */ + function Coin(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * Coin denom. + * @member {string} denom + * @memberof cosmos.base.v1beta1.Coin + * @instance + */ + Coin.prototype.denom = ""; + + /** + * Coin amount. + * @member {string} amount + * @memberof cosmos.base.v1beta1.Coin + * @instance + */ + Coin.prototype.amount = ""; + + /** + * Creates a new Coin instance using the specified properties. + * @function create + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {cosmos.base.v1beta1.ICoin=} [properties] Properties to set + * @returns {cosmos.base.v1beta1.Coin} Coin instance + */ + Coin.create = function create(properties) { + return new Coin(properties); + }; + + /** + * Encodes the specified Coin message. Does not implicitly {@link cosmos.base.v1beta1.Coin.verify|verify} messages. + * @function encode + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {cosmos.base.v1beta1.ICoin} message Coin message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Coin.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.denom != null && Object.hasOwnProperty.call(message, "denom")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.denom); + if (message.amount != null && Object.hasOwnProperty.call(message, "amount")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.amount); + return writer; + }; + + /** + * Encodes the specified Coin message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.Coin.verify|verify} messages. + * @function encodeDelimited + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {cosmos.base.v1beta1.ICoin} message Coin message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + Coin.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a Coin message from the specified reader or buffer. + * @function decode + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {cosmos.base.v1beta1.Coin} Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Coin.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.cosmos.base.v1beta1.Coin(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.denom = reader.string(); + break; + case 2: + message.amount = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a Coin message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {cosmos.base.v1beta1.Coin} Coin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + Coin.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a Coin message. + * @function verify + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + Coin.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.denom != null && message.hasOwnProperty("denom")) + if (!$util.isString(message.denom)) + return "denom: string expected"; + if (message.amount != null && message.hasOwnProperty("amount")) + if (!$util.isString(message.amount)) + return "amount: string expected"; + return null; + }; + + /** + * Creates a Coin message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {Object.} object Plain object + * @returns {cosmos.base.v1beta1.Coin} Coin + */ + Coin.fromObject = function fromObject(object) { + if (object instanceof $root.cosmos.base.v1beta1.Coin) + return object; + var message = new $root.cosmos.base.v1beta1.Coin(); + if (object.denom != null) + message.denom = String(object.denom); + if (object.amount != null) + message.amount = String(object.amount); + return message; + }; + + /** + * Creates a plain object from a Coin message. Also converts values to other types if specified. + * @function toObject + * @memberof cosmos.base.v1beta1.Coin + * @static + * @param {cosmos.base.v1beta1.Coin} message Coin + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + Coin.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.denom = ""; + object.amount = ""; + } + if (message.denom != null && message.hasOwnProperty("denom")) + object.denom = message.denom; + if (message.amount != null && message.hasOwnProperty("amount")) + object.amount = message.amount; + return object; + }; + + /** + * Converts this Coin to JSON. + * @function toJSON + * @memberof cosmos.base.v1beta1.Coin + * @instance + * @returns {Object.} JSON object + */ + Coin.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return Coin; + })(); + + v1beta1.DecCoin = (function() { + + /** + * Properties of a DecCoin. + * @memberof cosmos.base.v1beta1 + * @interface IDecCoin + * @property {string|null} [denom] DecCoin denom + * @property {string|null} [amount] DecCoin amount + */ + + /** + * Constructs a new DecCoin. + * @memberof cosmos.base.v1beta1 + * @classdesc Represents a DecCoin. + * @implements IDecCoin + * @constructor + * @param {cosmos.base.v1beta1.IDecCoin=} [properties] Properties to set + */ + function DecCoin(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * DecCoin denom. + * @member {string} denom + * @memberof cosmos.base.v1beta1.DecCoin + * @instance + */ + DecCoin.prototype.denom = ""; + + /** + * DecCoin amount. + * @member {string} amount + * @memberof cosmos.base.v1beta1.DecCoin + * @instance + */ + DecCoin.prototype.amount = ""; + + /** + * Creates a new DecCoin instance using the specified properties. + * @function create + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {cosmos.base.v1beta1.IDecCoin=} [properties] Properties to set + * @returns {cosmos.base.v1beta1.DecCoin} DecCoin instance + */ + DecCoin.create = function create(properties) { + return new DecCoin(properties); + }; + + /** + * Encodes the specified DecCoin message. Does not implicitly {@link cosmos.base.v1beta1.DecCoin.verify|verify} messages. + * @function encode + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {cosmos.base.v1beta1.IDecCoin} message DecCoin message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DecCoin.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.denom != null && Object.hasOwnProperty.call(message, "denom")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.denom); + if (message.amount != null && Object.hasOwnProperty.call(message, "amount")) + writer.uint32(/* id 2, wireType 2 =*/18).string(message.amount); + return writer; + }; + + /** + * Encodes the specified DecCoin message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.DecCoin.verify|verify} messages. + * @function encodeDelimited + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {cosmos.base.v1beta1.IDecCoin} message DecCoin message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DecCoin.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a DecCoin message from the specified reader or buffer. + * @function decode + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {cosmos.base.v1beta1.DecCoin} DecCoin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DecCoin.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.cosmos.base.v1beta1.DecCoin(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.denom = reader.string(); + break; + case 2: + message.amount = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a DecCoin message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {cosmos.base.v1beta1.DecCoin} DecCoin + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DecCoin.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a DecCoin message. + * @function verify + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + DecCoin.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.denom != null && message.hasOwnProperty("denom")) + if (!$util.isString(message.denom)) + return "denom: string expected"; + if (message.amount != null && message.hasOwnProperty("amount")) + if (!$util.isString(message.amount)) + return "amount: string expected"; + return null; + }; + + /** + * Creates a DecCoin message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {Object.} object Plain object + * @returns {cosmos.base.v1beta1.DecCoin} DecCoin + */ + DecCoin.fromObject = function fromObject(object) { + if (object instanceof $root.cosmos.base.v1beta1.DecCoin) + return object; + var message = new $root.cosmos.base.v1beta1.DecCoin(); + if (object.denom != null) + message.denom = String(object.denom); + if (object.amount != null) + message.amount = String(object.amount); + return message; + }; + + /** + * Creates a plain object from a DecCoin message. Also converts values to other types if specified. + * @function toObject + * @memberof cosmos.base.v1beta1.DecCoin + * @static + * @param {cosmos.base.v1beta1.DecCoin} message DecCoin + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + DecCoin.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) { + object.denom = ""; + object.amount = ""; + } + if (message.denom != null && message.hasOwnProperty("denom")) + object.denom = message.denom; + if (message.amount != null && message.hasOwnProperty("amount")) + object.amount = message.amount; + return object; + }; + + /** + * Converts this DecCoin to JSON. + * @function toJSON + * @memberof cosmos.base.v1beta1.DecCoin + * @instance + * @returns {Object.} JSON object + */ + DecCoin.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return DecCoin; + })(); + + v1beta1.IntProto = (function() { + + /** + * Properties of an IntProto. + * @memberof cosmos.base.v1beta1 + * @interface IIntProto + * @property {string|null} [int] IntProto int + */ + + /** + * Constructs a new IntProto. + * @memberof cosmos.base.v1beta1 + * @classdesc Represents an IntProto. + * @implements IIntProto + * @constructor + * @param {cosmos.base.v1beta1.IIntProto=} [properties] Properties to set + */ + function IntProto(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * IntProto int. + * @member {string} int + * @memberof cosmos.base.v1beta1.IntProto + * @instance + */ + IntProto.prototype.int = ""; + + /** + * Creates a new IntProto instance using the specified properties. + * @function create + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {cosmos.base.v1beta1.IIntProto=} [properties] Properties to set + * @returns {cosmos.base.v1beta1.IntProto} IntProto instance + */ + IntProto.create = function create(properties) { + return new IntProto(properties); + }; + + /** + * Encodes the specified IntProto message. Does not implicitly {@link cosmos.base.v1beta1.IntProto.verify|verify} messages. + * @function encode + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {cosmos.base.v1beta1.IIntProto} message IntProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + IntProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.int != null && Object.hasOwnProperty.call(message, "int")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.int); + return writer; + }; + + /** + * Encodes the specified IntProto message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.IntProto.verify|verify} messages. + * @function encodeDelimited + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {cosmos.base.v1beta1.IIntProto} message IntProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + IntProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes an IntProto message from the specified reader or buffer. + * @function decode + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {cosmos.base.v1beta1.IntProto} IntProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + IntProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.cosmos.base.v1beta1.IntProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.int = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes an IntProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {cosmos.base.v1beta1.IntProto} IntProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + IntProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies an IntProto message. + * @function verify + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + IntProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.int != null && message.hasOwnProperty("int")) + if (!$util.isString(message.int)) + return "int: string expected"; + return null; + }; + + /** + * Creates an IntProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {Object.} object Plain object + * @returns {cosmos.base.v1beta1.IntProto} IntProto + */ + IntProto.fromObject = function fromObject(object) { + if (object instanceof $root.cosmos.base.v1beta1.IntProto) + return object; + var message = new $root.cosmos.base.v1beta1.IntProto(); + if (object.int != null) + message.int = String(object.int); + return message; + }; + + /** + * Creates a plain object from an IntProto message. Also converts values to other types if specified. + * @function toObject + * @memberof cosmos.base.v1beta1.IntProto + * @static + * @param {cosmos.base.v1beta1.IntProto} message IntProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + IntProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.int = ""; + if (message.int != null && message.hasOwnProperty("int")) + object.int = message.int; + return object; + }; + + /** + * Converts this IntProto to JSON. + * @function toJSON + * @memberof cosmos.base.v1beta1.IntProto + * @instance + * @returns {Object.} JSON object + */ + IntProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return IntProto; + })(); + + v1beta1.DecProto = (function() { + + /** + * Properties of a DecProto. + * @memberof cosmos.base.v1beta1 + * @interface IDecProto + * @property {string|null} [dec] DecProto dec + */ + + /** + * Constructs a new DecProto. + * @memberof cosmos.base.v1beta1 + * @classdesc Represents a DecProto. + * @implements IDecProto + * @constructor + * @param {cosmos.base.v1beta1.IDecProto=} [properties] Properties to set + */ + function DecProto(properties) { + if (properties) + for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) + if (properties[keys[i]] != null) + this[keys[i]] = properties[keys[i]]; + } + + /** + * DecProto dec. + * @member {string} dec + * @memberof cosmos.base.v1beta1.DecProto + * @instance + */ + DecProto.prototype.dec = ""; + + /** + * Creates a new DecProto instance using the specified properties. + * @function create + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {cosmos.base.v1beta1.IDecProto=} [properties] Properties to set + * @returns {cosmos.base.v1beta1.DecProto} DecProto instance + */ + DecProto.create = function create(properties) { + return new DecProto(properties); + }; + + /** + * Encodes the specified DecProto message. Does not implicitly {@link cosmos.base.v1beta1.DecProto.verify|verify} messages. + * @function encode + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {cosmos.base.v1beta1.IDecProto} message DecProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DecProto.encode = function encode(message, writer) { + if (!writer) + writer = $Writer.create(); + if (message.dec != null && Object.hasOwnProperty.call(message, "dec")) + writer.uint32(/* id 1, wireType 2 =*/10).string(message.dec); + return writer; + }; + + /** + * Encodes the specified DecProto message, length delimited. Does not implicitly {@link cosmos.base.v1beta1.DecProto.verify|verify} messages. + * @function encodeDelimited + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {cosmos.base.v1beta1.IDecProto} message DecProto message or plain object to encode + * @param {$protobuf.Writer} [writer] Writer to encode to + * @returns {$protobuf.Writer} Writer + */ + DecProto.encodeDelimited = function encodeDelimited(message, writer) { + return this.encode(message, writer).ldelim(); + }; + + /** + * Decodes a DecProto message from the specified reader or buffer. + * @function decode + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @param {number} [length] Message length if known beforehand + * @returns {cosmos.base.v1beta1.DecProto} DecProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DecProto.decode = function decode(reader, length) { + if (!(reader instanceof $Reader)) + reader = $Reader.create(reader); + var end = length === undefined ? reader.len : reader.pos + length, message = new $root.cosmos.base.v1beta1.DecProto(); + while (reader.pos < end) { + var tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.dec = reader.string(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }; + + /** + * Decodes a DecProto message from the specified reader or buffer, length delimited. + * @function decodeDelimited + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from + * @returns {cosmos.base.v1beta1.DecProto} DecProto + * @throws {Error} If the payload is not a reader or valid buffer + * @throws {$protobuf.util.ProtocolError} If required fields are missing + */ + DecProto.decodeDelimited = function decodeDelimited(reader) { + if (!(reader instanceof $Reader)) + reader = new $Reader(reader); + return this.decode(reader, reader.uint32()); + }; + + /** + * Verifies a DecProto message. + * @function verify + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {Object.} message Plain object to verify + * @returns {string|null} `null` if valid, otherwise the reason why it is not + */ + DecProto.verify = function verify(message) { + if (typeof message !== "object" || message === null) + return "object expected"; + if (message.dec != null && message.hasOwnProperty("dec")) + if (!$util.isString(message.dec)) + return "dec: string expected"; + return null; + }; + + /** + * Creates a DecProto message from a plain object. Also converts values to their respective internal types. + * @function fromObject + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {Object.} object Plain object + * @returns {cosmos.base.v1beta1.DecProto} DecProto + */ + DecProto.fromObject = function fromObject(object) { + if (object instanceof $root.cosmos.base.v1beta1.DecProto) + return object; + var message = new $root.cosmos.base.v1beta1.DecProto(); + if (object.dec != null) + message.dec = String(object.dec); + return message; + }; + + /** + * Creates a plain object from a DecProto message. Also converts values to other types if specified. + * @function toObject + * @memberof cosmos.base.v1beta1.DecProto + * @static + * @param {cosmos.base.v1beta1.DecProto} message DecProto + * @param {$protobuf.IConversionOptions} [options] Conversion options + * @returns {Object.} Plain object + */ + DecProto.toObject = function toObject(message, options) { + if (!options) + options = {}; + var object = {}; + if (options.defaults) + object.dec = ""; + if (message.dec != null && message.hasOwnProperty("dec")) + object.dec = message.dec; + return object; + }; + + /** + * Converts this DecProto to JSON. + * @function toJSON + * @memberof cosmos.base.v1beta1.DecProto + * @instance + * @returns {Object.} JSON object + */ + DecProto.prototype.toJSON = function toJSON() { + return this.constructor.toObject(this, $protobuf.util.toJSONOptions); + }; + + return DecProto; + })(); + + return v1beta1; + })(); + + return base; + })(); + + return cosmos; +})(); + +module.exports = $root; diff --git a/packages/xchain-thorchain/src/util.ts b/packages/xchain-thorchain/src/util.ts index 47de2cc43..d3dae344f 100644 --- a/packages/xchain-thorchain/src/util.ts +++ b/packages/xchain-thorchain/src/util.ts @@ -1,3 +1,4 @@ +import { cosmosclient, proto } from '@cosmos-client/core' import { Address, Balance, FeeType, Fees, Network, TxHash, TxType, singleFee } from '@xchainjs/xchain-client' import { CosmosSDKClient, TxLog } from '@xchainjs/xchain-cosmos' import { @@ -12,13 +13,11 @@ import { isSynthAsset, } from '@xchainjs/xchain-util' import axios from 'axios' -import { AccAddress, Msg, codec } from 'cosmos-client' -import { StdTxFee } from 'cosmos-client/api' -import { StdTx } from 'cosmos-client/x/auth' -import { MsgMultiSend, MsgSend } from 'cosmos-client/x/bank' +import * as bech32Buffer from 'bech32-buffer' import { ChainId, ChainIds, ClientUrl, ExplorerUrl, ExplorerUrls, NodeInfoResponse, TxData } from './types' -import { MsgNativeTx, ThorchainDepositResponse } from './types/messages' +import { MsgNativeTx } from './types/messages' +import types from './types/proto/MsgCompiled' export const DECIMAL = 8 export const DEFAULT_GAS_VALUE = '3000000' @@ -57,26 +56,6 @@ export const assetFromDenom = (denom: string): Asset | null => { return assetFromString(denom.toUpperCase()) } -/** - * Type guard for MsgSend - * - * @param {Msg} msg - * @returns {boolean} `true` or `false`. - */ -export const isMsgSend = (msg: Msg): msg is MsgSend => - (msg as MsgSend)?.amount !== undefined && - (msg as MsgSend)?.from_address !== undefined && - (msg as MsgSend)?.to_address !== undefined - -/** - * Type guard for MsgMultiSend - * - * @param {Msg} msg - * @returns {boolean} `true` or `false`. - */ -export const isMsgMultiSend = (msg: Msg): msg is MsgMultiSend => - (msg as MsgMultiSend)?.inputs !== undefined && (msg as MsgMultiSend)?.outputs !== undefined - /** * Response guard for transaction broadcast * @@ -112,18 +91,17 @@ export const getPrefix = (network: Network) => { * * @param {string} prefix */ -export const registerCodecs = (prefix: string): void => { - codec.registerCodec('thorchain/MsgSend', MsgSend, MsgSend.fromJSON) - codec.registerCodec('thorchain/MsgMultiSend', MsgMultiSend, MsgMultiSend.fromJSON) - - AccAddress.setBech32Prefix( - prefix, - prefix + 'pub', - prefix + 'valoper', - prefix + 'valoperpub', - prefix + 'valcons', - prefix + 'valconspub', - ) +export const registerDespositCodecs = async (): Promise => { + cosmosclient.codec.register('/types.MsgDeposit', types.types.MsgDeposit) +} + +/** + * Register Codecs based on the prefix. + * + * @param {string} prefix + */ +export const registerSendCodecs = async (): Promise => { + cosmosclient.codec.register('/types.MsgSend', types.types.MsgSend) } /** @@ -219,7 +197,51 @@ export const getChainIds = async (client: ClientUrl): Promise => { } /** - * Structure StdTx from MsgNativeTx. + * Builds final unsigned TX + * + * @param cosmosSdk - CosmosSDK + * @param txBody - txBody with encoded Msgs + * @param signerPubkey - signerPubkey string + * @param sequence - account sequence + * @param gasLimit - transaction gas limit + * @returns + */ +export const buildUnsignedTx = ({ + cosmosSdk, + txBody, + signerPubkey, + sequence, + gasLimit, +}: { + cosmosSdk: cosmosclient.CosmosSDK + txBody: proto.cosmos.tx.v1beta1.TxBody + signerPubkey: proto.google.protobuf.Any + sequence: cosmosclient.Long + gasLimit: string +}): cosmosclient.TxBuilder => { + const authInfo = new proto.cosmos.tx.v1beta1.AuthInfo({ + signer_infos: [ + { + public_key: signerPubkey, + mode_info: { + single: { + mode: proto.cosmos.tx.signing.v1beta1.SignMode.SIGN_MODE_DIRECT, + }, + }, + sequence: sequence, + }, + ], + fee: { + amount: null, + gas_limit: cosmosclient.Long.fromString(gasLimit), + }, + }) + + return new cosmosclient.TxBuilder(cosmosSdk, txBody, authInfo) +} + +/** + * Structure a MsgDeposit * * @param {MsgNativeTx} msgNativeTx Msg of type `MsgNativeTx`. * @param {string} nodeUrl Node url @@ -237,35 +259,82 @@ export const buildDepositTx = async ({ msgNativeTx: MsgNativeTx nodeUrl: string chainId: ChainId -}): Promise => { +}): Promise => { const networkChainId = await getChainId(nodeUrl) - if (!networkChainId || chainId !== networkChainId) + if (!networkChainId || chainId !== networkChainId) { throw new Error(`Invalid network (asked: ${chainId} / returned: ${networkChainId}`) + } - const response: ThorchainDepositResponse = ( - await axios.post(`${nodeUrl}/thorchain/deposit`, { - coins: msgNativeTx.coins, - memo: msgNativeTx.memo, - base_req: { - chain_id: chainId, - from: msgNativeTx.signer, - }, - }) - ).data + const signerAddr = msgNativeTx.signer.toString() + const signerDecoded = bech32Buffer.decode(signerAddr) - if (!response || !response.value) throw new Error('Invalid client url') + const msgDepositObj = { + coins: msgNativeTx.coins, + memo: msgNativeTx.memo, + signer: signerDecoded.data, + } - const fee: StdTxFee = response.value?.fee ?? { amount: [] } + const depositMsg = types.types.MsgDeposit.fromObject(msgDepositObj) - const unsignedStdTx = StdTx.fromJSON({ - msg: response.value.msg, - // override fee - fee: { ...fee, gas: DEPOSIT_GAS_VALUE }, - signatures: [], - memo: '', + return new proto.cosmos.tx.v1beta1.TxBody({ + messages: [cosmosclient.codec.packAny(depositMsg)], + memo: msgNativeTx.memo, }) +} - return unsignedStdTx +/** + * Structure a MsgSend + * + * @param fromAddress - required, from address string + * @param toAddress - required, to address string + * @param assetAmount - required, asset amount string (e.g. "10000") + * @param assetDenom - required, asset denom string (e.g. "rune") + * @param memo - optional, memo string + * + * @returns + */ +export const buildTransferTx = async ({ + fromAddress, + toAddress, + assetAmount, + assetDenom, + memo = '', + nodeUrl, + chainId, +}: { + fromAddress: Address + toAddress: Address + assetAmount: BaseAmount + assetDenom: string + memo?: string + nodeUrl: string + chainId: ChainId +}): Promise => { + const networkChainId = await getChainId(nodeUrl) + if (!networkChainId || chainId !== networkChainId) { + throw new Error(`Invalid network (asked: ${chainId} / returned: ${networkChainId}`) + } + + const fromDecoded = bech32Buffer.decode(fromAddress) + const toDecoded = bech32Buffer.decode(toAddress) + + const transferObj = { + fromAddress: fromDecoded.data, + toAddress: toDecoded.data, + amount: [ + { + amount: assetAmount.amount().toString(), + denom: assetDenom, + }, + ], + } + + const transferMsg = types.types.MsgSend.fromObject(transferObj) + + return new proto.cosmos.tx.v1beta1.TxBody({ + messages: [cosmosclient.codec.packAny(transferMsg)], + memo, + }) } /** @@ -306,7 +375,7 @@ export const getDefaultClientUrl = (): ClientUrl => { return { [Network.Testnet]: { node: 'https://testnet.thornode.thorchain.info', - rpc: 'https://testnet.rpc.thorchain.info', + rpc: 'https://testnet-rpc.ninerealms.com', }, [Network.Stagenet]: { node: 'https://stagenet-thornode.ninerealms.com', @@ -314,7 +383,7 @@ export const getDefaultClientUrl = (): ClientUrl => { }, [Network.Mainnet]: { node: 'https://thornode.ninerealms.com', - rpc: 'https://rpc.thorchain.info', + rpc: 'https://rpc.ninerealms.com', }, } } diff --git a/tsconfig.json b/tsconfig.json index c47b34c5c..4179cbc72 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,19 +1,26 @@ { "extends": "./tsconfig.build.json", - "compilerOptions": { "baseUrl": ".", "paths": { - "@xchainjs/*": ["packages/*"] + "@xchainjs/*": [ + "packages/*" + ] }, "jsx": "react", - "types": ["jest", "node"], - - + "types": [ + "jest", + "node" + ], "outDir": "lib", "module": "esnext", - "target": "es5", - "lib": ["es6", "dom", "es2016", "es2017"], + "target": "es6", + "lib": [ + "es6", + "dom", + "es2016", + "es2017" + ], "importHelpers": true, "declaration": true, "strict": true, @@ -33,4 +40,4 @@ "allowSyntheticDefaultImports": true, "resolveJsonModule": true } -} +} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 672d0f928..86ece0098 100644 --- a/yarn.lock +++ b/yarn.lock @@ -332,6 +332,20 @@ exec-sh "^0.3.2" minimist "^1.2.0" +"@cosmos-client/core@^0.45.1": + version "0.45.1" + resolved "https://registry.yarnpkg.com/@cosmos-client/core/-/core-0.45.1.tgz#c57dbf861b7300203616362207fde24c58de6f32" + integrity sha512-AAf+UBwzcJvMpOFy6bBUGlF+wiGko32yekYtC/J3fxnC/NyAsOsqzPDLxgat6lveOfYESRdZslw78UMbKz7oQA== + dependencies: + axios "^0.23.0" + bech32 "^1.1.4" + bip32 "^2.0.6" + bip39 "^3.0.4" + protobufjs "^6.11.2" + rxjs "^7.4.0" + secp256k1 "^4.0.2" + tweetnacl "^1.0.3" + "@eslint/eslintrc@^0.2.1": version "0.2.1" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-0.2.1.tgz#f72069c330461a06684d119384435e12a5d76e3c" @@ -2942,13 +2956,20 @@ axios-mock-adapter@^1.20.0: is-blob "^2.1.0" is-buffer "^2.0.5" -axios@^0.19.0, axios@^0.19.2: +axios@^0.19.0: version "0.19.2" resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== dependencies: follow-redirects "1.5.10" +axios@^0.23.0: + version "0.23.0" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.23.0.tgz#b0fa5d0948a8d1d75e3d5635238b6c4625b05149" + integrity sha512-NmvAE4i0YAv5cKq8zlDoPd1VLKAqX5oLuZKs8xkJa4qi6RGn0uhCYFjWtHHC9EM/MwOwYWOs53W+V0aqEXq1sg== + dependencies: + follow-redirects "^1.14.4" + axios@^0.24.0: version "0.24.0" resolved "https://registry.yarnpkg.com/axios/-/axios-0.24.0.tgz#804e6fa1e4b9c5288501dd9dff56a7a0940d20d6" @@ -3071,7 +3092,12 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" -bech32@1.1.4, bech32@^1.1.2, bech32@^1.1.3: +bech32-buffer@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/bech32-buffer/-/bech32-buffer-0.2.0.tgz#c0565f0045eea0ffd510846680dda4e31a1d944e" + integrity sha512-Ez8s82a+Xnn/m3/ftGaQJUSFG4EwNIj9adIJBw8OrHASQsXgvwLSducbcJ9El0rsrwJYJ71yBhC/hZzz3FPSCQ== + +bech32@1.1.4, bech32@^1.1.2, bech32@^1.1.3, bech32@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9" integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ== @@ -3951,19 +3977,6 @@ cosmiconfig@^7.0.0: path-type "^4.0.0" yaml "^1.10.0" -cosmos-client@0.39.2: - version "0.39.2" - resolved "https://registry.yarnpkg.com/cosmos-client/-/cosmos-client-0.39.2.tgz#332da4a8b5935c5309afb03f2fd6de808a4e35f0" - integrity sha512-ISGmjrQA5dpJfRi289fQQIrrhcb7R79fPmvWGG1iOjjIaT++h5nMxE8upmVTsxYPSJZxLEntbQgKeeZ3HaY8PA== - dependencies: - axios "^0.19.2" - bech32 "^1.1.3" - bip32 "^2.0.5" - bip39 "^3.0.2" - sr25519 "^0.2.0" - tiny-secp256k1 "^1.1.3" - tweetnacl "^1.0.1" - create-ecdh@^4.0.0: version "4.0.4" resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.4.tgz#d6e7f4bffa66736085a0762fd3a632684dabcc4e" @@ -8238,7 +8251,7 @@ proto-list@~1.2.1: resolved "https://registry.yarnpkg.com/proto-list/-/proto-list-1.2.4.tgz#212d5bfe1318306a420f6402b8e26ff39647a849" integrity sha1-IS1b/hMYMGpCD2QCuOJv85ZHqEk= -protobufjs@~6.11.2: +protobufjs@^6.11.2, protobufjs@~6.11.2: version "6.11.2" resolved "https://registry.yarnpkg.com/protobufjs/-/protobufjs-6.11.2.tgz#de39fabd4ed32beaa08e9bb1e30d08544c1edf8b" integrity sha512-4BQJoPooKJl2G9j3XftkIXjoC9C0Av2NOrWmbLWT1vH32GcSUHjM0Arra6UfTsVyfMAuFzaLucXn1sadxJydAw== @@ -8854,6 +8867,13 @@ rxjs@^6.4.0, rxjs@^6.6.3: dependencies: tslib "^1.9.0" +rxjs@^7.4.0: + version "7.5.5" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.5.5.tgz#2ebad89af0f560f460ad5cc4213219e1f7dd4e9f" + integrity sha512-sy+H0pQofO95VDmFLzyaw9xNJU4KTRSwQIGM6+iG3SypAtCiLDzpeG8sJrNCWn2Up9km+KhkvTdbkrdy+yzZdw== + dependencies: + tslib "^2.1.0" + safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@^5.2.0, safe-buffer@~5.2.0: version "5.2.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.2.1.tgz#1eaf9fa9bdb1fdd4ec75f58f9cdb4e6b7827eec6" @@ -9233,11 +9253,6 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= -sr25519@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/sr25519/-/sr25519-0.2.0.tgz#80e1632c1e7c07eae00cf5303dc804d87e76fb15" - integrity sha512-dRyJ09XOOl6tBRwQ3ZwkukyvhY3mHLC5k45aBBp+xjKEpjPPU4oL2JCQqisNhL96/gzwsI1PMxZ52svfQurNLw== - sshpk@^1.7.0: version "1.16.1" resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.16.1.tgz#fb661c0bef29b39db40769ee39fa70093d6f6877" @@ -9807,7 +9822,7 @@ tweetnacl@^0.14.3, tweetnacl@~0.14.0: resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" integrity sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q= -tweetnacl@^1.0.1, tweetnacl@^1.0.3: +tweetnacl@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==