1
- import { CONTRACTS } from '@certusone/wormhole-sdk/lib/cjs/utils/consts' ;
1
+ import { CONTRACTS , Contracts } from '@certusone/wormhole-sdk/lib/cjs/utils/consts' ;
2
2
import axios from 'axios' ;
3
- import { AXIOS_CONFIG_JSON , SEI_EXPLORER_GRAPHQL , SEI_EXPLORER_TXS } from '../consts' ;
3
+ import {
4
+ AXIOS_CONFIG_JSON ,
5
+ SEI_EXPLORER_GRAPHQL_MAINNET ,
6
+ SEI_EXPLORER_GRAPHQL_TESTNET ,
7
+ SEI_EXPLORER_TXS_MAINNET ,
8
+ SEI_EXPLORER_TXS_TESTNET ,
9
+ } from '../consts' ;
4
10
import { VaasByBlock } from '../databases/types' ;
5
11
import { makeBlockKey , makeVaaKey } from '../databases/utils' ;
6
12
import { CosmwasmHashResult , CosmwasmWatcher } from './CosmwasmWatcher' ;
@@ -29,33 +35,65 @@ type SeiExplorerAccountTransactionsResponse = {
29
35
} ;
30
36
31
37
export class SeiExplorerWatcher extends CosmwasmWatcher {
38
+ explorerGraphql : string ;
39
+ explorerTxs : string ;
40
+ accountId : number ;
41
+
32
42
constructor ( network : Environment ) {
33
43
super ( network , 'sei' ) ;
34
44
// arbitrarily large since the code here is capable of pulling all logs from all via indexer pagination
35
45
this . maximumBatchSize = 1_000_000 ;
46
+ this . explorerGraphql =
47
+ network === 'mainnet'
48
+ ? SEI_EXPLORER_GRAPHQL_MAINNET
49
+ : network === 'testnet'
50
+ ? SEI_EXPLORER_GRAPHQL_TESTNET
51
+ : '' ;
52
+ this . explorerTxs =
53
+ network === 'mainnet'
54
+ ? SEI_EXPLORER_TXS_MAINNET
55
+ : network === 'testnet'
56
+ ? SEI_EXPLORER_TXS_TESTNET
57
+ : '' ;
58
+ this . accountId = network === 'mainnet' ? 42 : network === 'testnet' ? 3254150 : 0 ;
59
+ // 42 is the account id of sei1gjrrme22cyha4ht2xapn3f08zzw6z3d4uxx6fyy9zd5dyr3yxgzqqncdqn <-- mainnet
60
+ // MAINNET:
61
+ // curl https://pacific-1-graphql.alleslabs.dev/v1/graphql \
62
+ // -X POST \
63
+ // -H "Content-Type: application/json" \
64
+ // --data '{"query":"query getAccountIdByAddressQueryDocument($address: String!) {accounts_by_pk(address: $address) {id}}", "variables":{"address":"sei1gjrrme22cyha4ht2xapn3f08zzw6z3d4uxx6fyy9zd5dyr3yxgzqqncdqn"}, "operationName":"getAccountIdByAddressQueryDocument" }'
65
+ // {"data":{"accounts_by_pk":{"id":42}}}
66
+ //
67
+ // 3254150 is the account number of sei1nna9mzp274djrgzhzkac2gvm3j27l402s4xzr08chq57pjsupqnqaj0d5s <-- testnet
68
+ // TESTNET:
69
+ // curl https://atlantic-2-graphql.alleslabs.dev/v1/graphql \
70
+ // -X POST \
71
+ // -H "Content-Type: application/json" \
72
+ // --data '{"query":"query getAccountIdByAddressQueryDocument($address: String!) {accounts_by_pk(address: $address) {id}}", "variables":{"address":"sei1nna9mzp274djrgzhzkac2gvm3j27l402s4xzr08chq57pjsupqnqaj0d5s"}, "operationName":"getAccountIdByAddressQueryDocument" }'
73
+ // {"data":{"accounts_by_pk":{"id":3254150}}}
74
+ // returned by getAccountIdByAddressQueryDocument
36
75
}
37
76
38
77
makeGraphQLQuery ( offset : number , pageSize : number ) {
39
78
return {
40
79
query :
41
80
'query getTxsByAddressPagination($expression: account_transactions_bool_exp, $offset: Int!, $pageSize: Int!) {\n account_transactions(\n where: $expression\n order_by: {block_height: desc}\n offset: $offset\n limit: $pageSize\n ) {\n block {\n height\n timestamp\n }\n transaction {\n account {\n address\n }\n hash\n success\n messages\n is_clear_admin\n is_execute\n is_ibc\n is_instantiate\n is_migrate\n is_send\n is_store_code\n is_update_admin\n }\n is_signer\n }\n}' ,
42
- variables : { expression : { account_id : { _eq : 42 } } , offset, pageSize } ,
43
- // 42 is the account id of sei1gjrrme22cyha4ht2xapn3f08zzw6z3d4uxx6fyy9zd5dyr3yxgzqqncdqn
44
- // returned by getAccountIdByAddressQueryDocument
81
+ variables : { expression : { account_id : { _eq : this . accountId } } , offset, pageSize } ,
45
82
operationName : 'getTxsByAddressPagination' ,
46
83
} ;
47
84
}
48
85
49
86
async getFinalizedBlockNumber ( ) : Promise < number > {
50
87
const query = this . makeGraphQLQuery ( 0 , 1 ) ;
51
- this . logger . debug ( `Query string = ${ JSON . stringify ( query ) } ` ) ;
88
+ // this.logger.debug(`Query string = ${JSON.stringify(query)}`);
52
89
const bulkTxnResult = (
53
90
await axios . post < SeiExplorerAccountTransactionsResponse > (
54
- SEI_EXPLORER_GRAPHQL ,
91
+ this . explorerGraphql ,
55
92
query ,
56
93
AXIOS_CONFIG_JSON
57
94
)
58
95
) . data ;
96
+ this . logger . debug ( `bulkTxnResult = ${ JSON . stringify ( bulkTxnResult ) } ` ) ;
59
97
const blockHeight = bulkTxnResult ?. data ?. account_transactions ?. [ 0 ] ?. block ?. height ;
60
98
if ( blockHeight ) {
61
99
if ( blockHeight !== this . latestBlockHeight ) {
@@ -70,7 +108,13 @@ export class SeiExplorerWatcher extends CosmwasmWatcher {
70
108
// retrieve blocks for core contract
71
109
// compare block height with what is passed in
72
110
async getMessagesForBlocks ( fromBlock : number , toBlock : number ) : Promise < VaasByBlock > {
73
- const address = CONTRACTS . MAINNET [ this . chain ] . core ;
111
+ const contracts : Contracts =
112
+ this . network === 'mainnet'
113
+ ? CONTRACTS . MAINNET [ this . chain ]
114
+ : this . network === 'testnet'
115
+ ? CONTRACTS . TESTNET [ this . chain ]
116
+ : CONTRACTS . DEVNET [ this . chain ] ;
117
+ const address = contracts . core ;
74
118
if ( ! address ) {
75
119
throw new Error ( `Core contract not defined for ${ this . chain } ` ) ;
76
120
}
@@ -83,10 +127,10 @@ export class SeiExplorerWatcher extends CosmwasmWatcher {
83
127
let skip : number = 0 ;
84
128
while ( ! done ) {
85
129
const query = this . makeGraphQLQuery ( skip , limit ) ;
86
- this . logger . debug ( `Query string = ${ JSON . stringify ( query ) } ` ) ;
130
+ // this.logger.debug(`Query string = ${JSON.stringify(query)}`);
87
131
const bulkTxnResult = (
88
132
await axios . post < SeiExplorerAccountTransactionsResponse > (
89
- SEI_EXPLORER_GRAPHQL ,
133
+ this . explorerGraphql ,
90
134
query ,
91
135
AXIOS_CONFIG_JSON
92
136
)
@@ -130,7 +174,7 @@ export class SeiExplorerWatcher extends CosmwasmWatcher {
130
174
} catch ( e : any ) {
131
175
if ( e ?. response ?. status === 404 ) {
132
176
// the node is mysteriously missing some transactions, but so is this ='(
133
- hashResult = ( await axios . get ( `${ SEI_EXPLORER_TXS } ${ hash } ` , AXIOS_CONFIG_JSON ) )
177
+ hashResult = ( await axios . get ( `${ this . explorerTxs } ${ hash } ` , AXIOS_CONFIG_JSON ) )
134
178
. data ;
135
179
}
136
180
}
0 commit comments