-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(txs-tracer-core): ✨ improve tx trace machine
improved tx trace machine state structer and add websocket query to rpc node.
- Loading branch information
1 parent
2cb93a9
commit 31c6000
Showing
8 changed files
with
159 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './types'; | ||
export * from './machines'; | ||
export * from './utils'; |
69 changes: 55 additions & 14 deletions
69
packages/txs-tracer-core/src/lib/machines/txs-trace-machine/txs-trace-machine.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,60 @@ | ||
import { interpret } from 'xstate'; | ||
import { txTraceMachine } from './txs-trace-machine'; | ||
|
||
test('should eventually reach "pending"', () => | ||
new Promise<void>(done => { | ||
const fetchService = interpret(txTraceMachine).onTransition(state => { | ||
if (state.matches('pending')) { | ||
done(); | ||
} | ||
}); | ||
describe('txs-trace-machine', () => { | ||
test('should eventually reach "pending_subscription"', () => | ||
new Promise<void>(done => { | ||
const fetchService = interpret( | ||
txTraceMachine.withContext({ | ||
...txTraceMachine.context, | ||
}), | ||
) | ||
.onTransition(state => { | ||
console.log(state.value); | ||
if (state.matches('pending_subscription')) { | ||
done(); | ||
} | ||
}) | ||
.onEvent(event => { | ||
console.log(event.type); | ||
}); | ||
|
||
fetchService.start(); | ||
fetchService.start(); | ||
|
||
/* | ||
* Send zero or more events to the service that should | ||
* cause it to eventually reach its expected state | ||
*/ | ||
fetchService.send({ type: 'TRACE' }); | ||
})); | ||
/* | ||
* Send zero or more events to the service that should | ||
* cause it to eventually reach its expected state | ||
*/ | ||
fetchService.send({ type: 'TRACE' }); | ||
})); | ||
|
||
test( | ||
'should eventually reach "results"', | ||
() => | ||
new Promise<void>(done => { | ||
const fetchService = interpret( | ||
txTraceMachine.withContext({ | ||
...txTraceMachine.context, | ||
subscribeTimeout: 1000, | ||
query: "message.action='/osmosis.gamm.v1beta1.MsgSwapExactAmountIn'", | ||
}), | ||
).onTransition(state => { | ||
if (state.matches('results')) { | ||
console.log(state.context.txs); | ||
done(); | ||
} | ||
}); | ||
|
||
fetchService.start(); | ||
|
||
/* | ||
* Send zero or more events to the service that should | ||
* cause it to eventually reach its expected state | ||
*/ | ||
fetchService.send({ type: 'TRACE' }); | ||
}), | ||
{ | ||
timeout: 30_000, | ||
}, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
import { IndexedTx } from '@cosmjs/stargate'; | ||
import { Tendermint34Client } from '@cosmjs/tendermint-rpc'; | ||
|
||
export interface TxTraceContext { | ||
txTimeout: number; | ||
subscribeTimeout: number; | ||
connectionTimeout: number; | ||
websocketUrl: string; | ||
query: string; | ||
method: string; | ||
txs: IndexedTx[]; | ||
tendermintClient?: Tendermint34Client; | ||
} | ||
|
||
export type TxTraceEvents = | ||
| { type: 'TX_RESULTS' } | ||
| { type: 'CONNECTION_SUCCESS' } | ||
| { type: 'CONNECTION_ERROR' } | ||
| { type: 'SEND_QUERY_MESSAGE' } | ||
| { type: 'CONNECTION_DISCONNECT' } | ||
| { type: 'TRACE' } | ||
| { type: 'TX_SEARCH_EMPTY' }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './tx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { TxEvent, TxResponse } from '@cosmjs/tendermint-rpc'; | ||
import { fromTendermint34Event, IndexedTx } from '@cosmjs/stargate'; | ||
import { toHex } from '@cosmjs/encoding'; | ||
|
||
export const mapIndexedTx = (tx: TxResponse | TxEvent): IndexedTx => ({ | ||
height: tx.height, | ||
hash: toHex(tx.hash).toUpperCase(), | ||
code: tx.result.code, | ||
events: tx.result.events.map(fromTendermint34Event), | ||
rawLog: tx.result.log || '', | ||
tx: tx.tx, | ||
gasUsed: tx.result.gasUsed, | ||
gasWanted: tx.result.gasWanted, | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.