@xchainjs/xchain-thorchain 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -127572,9 +127572,9 @@ var types = /*@__PURE__*/getDefaultExportFromCjs(MsgCompiled);
127572
127572
  */
127573
127573
  const getDefaultClientUrls = () => {
127574
127574
  return {
127575
- [xchainClient.Network.Testnet]: 'deprecated',
127576
- [xchainClient.Network.Stagenet]: 'https://stagenet-rpc.ninerealms.com',
127577
- [xchainClient.Network.Mainnet]: 'https://rpc-v1.ninerealms.com',
127575
+ [xchainClient.Network.Testnet]: ['deprecated'],
127576
+ [xchainClient.Network.Stagenet]: ['https://stagenet-rpc.ninerealms.com'],
127577
+ [xchainClient.Network.Mainnet]: ['https://rpc-v1.ninerealms.com'],
127578
127578
  };
127579
127579
  };
127580
127580
  /**
@@ -127781,13 +127781,7 @@ class Client extends xchainCosmosSdk.Client {
127781
127781
  prefix: this.prefix,
127782
127782
  hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(params.walletIndex || 0))],
127783
127783
  });
127784
- const signingClient = yield build$7.SigningStargateClient.connectWithSigner(this.clientUrls[this.network], signer, {
127785
- registry: this.registry,
127786
- });
127787
- const messages = unsignedTx.body.messages.map((message) => {
127788
- return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
127789
- });
127790
- const tx = yield signingClient.signAndBroadcast(sender, messages, this.getStandardFee(), unsignedTx.body.memo);
127784
+ const tx = yield this.roundRobinSignAndBroadcastTx(sender, unsignedTx, signer);
127791
127785
  return tx.transactionHash;
127792
127786
  });
127793
127787
  }
@@ -127932,29 +127926,7 @@ class Client extends xchainCosmosSdk.Client {
127932
127926
  prefix: this.prefix,
127933
127927
  hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex || 0))],
127934
127928
  });
127935
- // Connect to signing client
127936
- const signingClient = yield build$7.SigningStargateClient.connectWithSigner(this.clientUrls[this.network], signer, {
127937
- registry: this.registry,
127938
- });
127939
- // Sign and broadcast transaction
127940
- const tx = yield signingClient.signAndBroadcast(sender, [
127941
- {
127942
- typeUrl: MSG_DEPOSIT_TYPE_URL,
127943
- value: {
127944
- signer: xchainCosmosSdk.bech32ToBase64(sender),
127945
- memo,
127946
- coins: [
127947
- {
127948
- amount: amount.amount().toString(),
127949
- asset,
127950
- },
127951
- ],
127952
- },
127953
- },
127954
- ], {
127955
- amount: [],
127956
- gas: gasLimit.toString(),
127957
- }, memo);
127929
+ const tx = yield this.roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset);
127958
127930
  return tx.transactionHash;
127959
127931
  });
127960
127932
  }
@@ -127982,19 +127954,7 @@ class Client extends xchainCosmosSdk.Client {
127982
127954
  prefix: this.prefix,
127983
127955
  hdPaths: [xchainCosmosSdk.makeClientPath(this.getFullDerivationPath(walletIndex))],
127984
127956
  });
127985
- // Connect to signing client
127986
- const signingClient = yield build$7.SigningStargateClient.connectWithSigner(this.clientUrls[this.network], signer, {
127987
- registry: this.registry,
127988
- });
127989
- // Prepare messages
127990
- const messages = unsignedTx.body.messages.map((message) => {
127991
- return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
127992
- });
127993
- // Sign transaction
127994
- const rawTx = yield signingClient.sign(sender, messages, {
127995
- amount: [],
127996
- gas: gasLimit.toString(),
127997
- }, unsignedTx.body.memo);
127957
+ const rawTx = yield this.roundRobinSign(sender, unsignedTx, signer, gasLimit);
127998
127958
  // Return encoded signed transaction
127999
127959
  return encoding.toBase64(tx$1.TxRaw.encode(rawTx).finish());
128000
127960
  });
@@ -128077,6 +128037,100 @@ class Client extends xchainCosmosSdk.Client {
128077
128037
  return crypto$3.createHash('ripemd160').update(sha256Hash).digest();
128078
128038
  }
128079
128039
  }
128040
+ /**
128041
+ * Sign a transaction making a round robin over the clients urls provided to the client
128042
+ *
128043
+ * @param {string} sender Sender address
128044
+ * @param {DecodedTxRaw} unsignedTx Unsigned transaction
128045
+ * @param {DirectSecp256k1HdWallet} signer Signer
128046
+ * @param {BigNumber} gasLimit Transaction gas limit
128047
+ * @returns {TxRaw} The raw signed transaction
128048
+ */
128049
+ roundRobinSign(sender, unsignedTx, signer, gasLimit) {
128050
+ return __awaiter(this, void 0, void 0, function* () {
128051
+ // Connect to signing client
128052
+ for (const url of this.clientUrls[this.network]) {
128053
+ const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128054
+ registry: this.registry,
128055
+ });
128056
+ // Prepare messages
128057
+ const messages = unsignedTx.body.messages.map((message) => {
128058
+ return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
128059
+ });
128060
+ // Sign transaction
128061
+ return yield signingClient.sign(sender, messages, {
128062
+ amount: [],
128063
+ gas: gasLimit.toString(),
128064
+ }, unsignedTx.body.memo);
128065
+ }
128066
+ throw Error('No clients available. Can not sign transaction');
128067
+ });
128068
+ }
128069
+ /**
128070
+ * Sign and broadcast a transaction making a round robin over the clients urls provided to the client
128071
+ *
128072
+ * @param {string} sender Sender address
128073
+ * @param {DecodedTxRaw} unsignedTx Unsigned transaction
128074
+ * @param {DirectSecp256k1HdWallet} signer Signer
128075
+ * @returns {DeliverTxResponse} The transaction broadcasted
128076
+ */
128077
+ roundRobinSignAndBroadcastTx(sender, unsignedTx, signer) {
128078
+ return __awaiter(this, void 0, void 0, function* () {
128079
+ for (const url of this.clientUrls[this.network]) {
128080
+ const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128081
+ registry: this.registry,
128082
+ });
128083
+ const messages = unsignedTx.body.messages.map((message) => {
128084
+ return { typeUrl: this.getMsgTypeUrlByType(xchainCosmosSdk.MsgTypes.TRANSFER), value: signingClient.registry.decode(message) };
128085
+ });
128086
+ return yield signingClient.signAndBroadcast(sender, messages, this.getStandardFee(), unsignedTx.body.memo);
128087
+ }
128088
+ throw Error('No clients available. Can not sign and broadcast transaction');
128089
+ });
128090
+ }
128091
+ /**
128092
+ * Sign and broadcast a transaction making a round robin over the clients urls provided to the client
128093
+ *
128094
+ * @param {string} sender Sender address
128095
+ * @param {DirectSecp256k1HdWallet} signer Signer
128096
+ * @param {BigNumber} gasLimit Gas limit for the transaction
128097
+ * @param {BaseAmount} amount Amount to deposit
128098
+ * @param {string} memo Deposit memo
128099
+ * @param {Asset} asset Asset to deposit
128100
+ * @returns {DeliverTxResponse} The transaction broadcasted
128101
+ */
128102
+ roundRobinSignAndBroadcastDeposit(sender, signer, gasLimit, amount, memo, asset) {
128103
+ return __awaiter(this, void 0, void 0, function* () {
128104
+ for (const url of this.clientUrls[this.network]) {
128105
+ try {
128106
+ const signingClient = yield build$7.SigningStargateClient.connectWithSigner(url, signer, {
128107
+ registry: this.registry,
128108
+ });
128109
+ // Sign and broadcast transaction
128110
+ return yield signingClient.signAndBroadcast(sender, [
128111
+ {
128112
+ typeUrl: MSG_DEPOSIT_TYPE_URL,
128113
+ value: {
128114
+ signer: xchainCosmosSdk.bech32ToBase64(sender),
128115
+ memo,
128116
+ coins: [
128117
+ {
128118
+ amount: amount.amount().toString(),
128119
+ asset,
128120
+ },
128121
+ ],
128122
+ },
128123
+ },
128124
+ ], {
128125
+ amount: [],
128126
+ gas: gasLimit.toString(),
128127
+ }, memo);
128128
+ }
128129
+ catch (_a) { }
128130
+ }
128131
+ throw Error('No clients available. Can not sign and broadcast deposit transaction');
128132
+ });
128133
+ }
128080
128134
  }
128081
128135
 
128082
128136
  exports.AssetRuneNative = AssetRuneNative;