@rango-dev/provider-walletconnect-2 0.1.1-next.0
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/dist/constants.d.ts +53 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/helpers.d.ts +20 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +7 -0
- package/dist/session.d.ts +63 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/signer.d.ts +4 -0
- package/dist/signer.d.ts.map +1 -0
- package/dist/signers/cosmos.d.ts +16 -0
- package/dist/signers/cosmos.d.ts.map +1 -0
- package/dist/signers/evm.d.ts +16 -0
- package/dist/signers/evm.d.ts.map +1 -0
- package/dist/signers/helper.d.ts +3 -0
- package/dist/signers/helper.d.ts.map +1 -0
- package/dist/signers/mock.d.ts +3 -0
- package/dist/signers/mock.d.ts.map +1 -0
- package/dist/signers/solana.d.ts +15 -0
- package/dist/signers/solana.d.ts.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +41 -0
- package/readme.md +10 -0
- package/src/constants.ts +83 -0
- package/src/helpers.ts +165 -0
- package/src/index.ts +177 -0
- package/src/session.ts +308 -0
- package/src/signer.ts +32 -0
- package/src/signers/cosmos.ts +243 -0
- package/src/signers/evm.ts +134 -0
- package/src/signers/helper.ts +73 -0
- package/src/signers/mock.ts +3675 -0
- package/src/signers/solana.ts +155 -0
- package/src/types.ts +25 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { TendermintTxTracer } from '@keplr-wallet/cosmos';
|
|
2
|
+
import { simpleFetch } from '@keplr-wallet/simple-fetch';
|
|
3
|
+
import { BlockchainMeta, cosmosBlockchains } from 'rango-types';
|
|
4
|
+
export async function sendTx(
|
|
5
|
+
chainId: string,
|
|
6
|
+
tx: unknown,
|
|
7
|
+
mode: 'async' | 'sync' | 'block',
|
|
8
|
+
supportedChains: BlockchainMeta[]
|
|
9
|
+
): Promise<Uint8Array> {
|
|
10
|
+
console.log({ chainId, tx, mode });
|
|
11
|
+
|
|
12
|
+
const cosmos = cosmosBlockchains(supportedChains);
|
|
13
|
+
const chainInfo = cosmos.find((item) => item.chainId === chainId)?.info;
|
|
14
|
+
const isProtoTx = Buffer.isBuffer(tx) || tx instanceof Uint8Array;
|
|
15
|
+
|
|
16
|
+
console.log({ chainInfo, isProtoTx });
|
|
17
|
+
|
|
18
|
+
if (!chainInfo) {
|
|
19
|
+
throw 'Chain info is undefined from server';
|
|
20
|
+
}
|
|
21
|
+
const params = isProtoTx
|
|
22
|
+
? {
|
|
23
|
+
tx_bytes: Buffer.from(tx as any).toString('base64'),
|
|
24
|
+
mode: (() => {
|
|
25
|
+
switch (mode) {
|
|
26
|
+
case 'async':
|
|
27
|
+
return 'BROADCAST_MODE_ASYNC';
|
|
28
|
+
case 'block':
|
|
29
|
+
return 'BROADCAST_MODE_BLOCK';
|
|
30
|
+
case 'sync':
|
|
31
|
+
return 'BROADCAST_MODE_SYNC';
|
|
32
|
+
default:
|
|
33
|
+
return 'BROADCAST_MODE_UNSPECIFIED';
|
|
34
|
+
}
|
|
35
|
+
})(),
|
|
36
|
+
}
|
|
37
|
+
: {
|
|
38
|
+
tx,
|
|
39
|
+
mode: mode,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
const result = await simpleFetch<any>(
|
|
44
|
+
chainInfo.rest,
|
|
45
|
+
isProtoTx ? '/cosmos/tx/v1beta1/txs' : '/txs',
|
|
46
|
+
{
|
|
47
|
+
method: 'POST',
|
|
48
|
+
headers: {
|
|
49
|
+
'content-type': 'application/json',
|
|
50
|
+
},
|
|
51
|
+
body: JSON.stringify(params),
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const txResponse = isProtoTx ? result.data['tx_response'] : result.data;
|
|
56
|
+
|
|
57
|
+
if (txResponse.code != null && txResponse.code !== 0) {
|
|
58
|
+
throw new Error(txResponse['raw_log']);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const txHash = Buffer.from(txResponse.txhash, 'hex');
|
|
62
|
+
|
|
63
|
+
const txTracer = new TendermintTxTracer(chainInfo.rpc, '/websocket');
|
|
64
|
+
txTracer.traceTx(txHash).then(() => {
|
|
65
|
+
txTracer.close();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
return txHash;
|
|
69
|
+
} catch (e) {
|
|
70
|
+
console.log(e);
|
|
71
|
+
throw e;
|
|
72
|
+
}
|
|
73
|
+
}
|