Skip to content

Commit 4827992

Browse files
committed
[tx_builder] construct extrinsic based on finalized block data
1 parent db1ebd7 commit 4827992

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/lib/service/tx/lib/src/tx_builder.dart

+12-5
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class TxBuilder {
3131

3232
// fetch recent relevant data from chain
3333
final runtimeVersion = await _getRuntimeVersion();
34-
final blockNumber = await _getBlockNumber();
35-
final blockHash = await _getBlockHash(blockNumber: blockNumber);
34+
final finalizedHash = await _getLatestFinalizedHash();
35+
final blockNumber = await _getBlockNumber(hash: finalizedHash);
3636
final genesisHash = await _getBlockHash(blockNumber: 0);
3737
final accountInfo = await encointerKusama.query.system.account(pair.publicKey.bytes);
3838

@@ -49,7 +49,7 @@ class TxBuilder {
4949
specVersion: runtimeVersion.specVersion,
5050
transactionVersion: runtimeVersion.transactionVersion,
5151
genesisHash: genesisHash,
52-
blockHash: blockHash,
52+
blockHash: finalizedHash,
5353
blockNumber: blockNumber,
5454
eraPeriod: 64,
5555
nonce: accountInfo.nonce,
@@ -85,8 +85,15 @@ class TxBuilder {
8585
return hash.replaceFirst('0x', '');
8686
}
8787

88-
Future<int> _getBlockNumber() async {
89-
final block = await provider.send('chain_getBlock', []);
88+
Future<String> _getLatestFinalizedHash() async {
89+
final hash = (await provider.send('chain_getFinalizedHead', [])).result as String;
90+
return hash.replaceFirst('0x', '');
91+
}
92+
93+
Future<int> _getBlockNumber({String? hash}) async {
94+
final params = hash != null ? [hash.replaceFirst('0x', '')] : <String>[];
95+
96+
final block = await provider.send('chain_getBlock', params);
9097

9198
// ignore: avoid_dynamic_calls
9299
final blockNumber = int.parse(block.result['block']['header']['number'] as String);

0 commit comments

Comments
 (0)