Empty Header on RPC events
mattlockyer opened this issue · 3 comments
When listening for transaction receipts and confirmations, there is no block number returned from the socketConfirmation data. This causes the JS SDK to throw an error.
const blockNumber =
this.messenger.chainPrefix === 'hmy'
? data.params.result.Header.number
: data.params.result.number;
The value of data.params.result.Header
is {}
causing number to be undefined.
This is a new issue based on upgrades to the core protocol recently (since Dec 15, 2019).
Please link to possible related issues
Example when calling contract method:
const tx = contract.methods.transfer(address, new hmy.utils.Unit(amount).asEther().toWei()).send({
from: active.address,
gasLimit: '1000000',
gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
}).on('transactionHash', function(hash){
console.log(hash)
}).on('receipt', function(receipt){
console.log(receipt)
}).on('confirmation', function(confirmationNumber, receipt){
console.log(confirmationNumber, receipt)
dispatch(getBalances(active))
dispatch(updateProcessing(false))
}).on('error', console.error)
Using websockets.
transactionHash
works fine.
receipt
event never fires because SDK throws error.
@mattlockyer Since core protocol changes a couple times at this part. We might need to confirm with all testnets and mainnet.
Will solve it on Monday.
I can still reproduce with the latest upstream master from harmony repo (running localnet)
p.onData(async (data: any) => {
//change block number to let vs. const so we can set if undefined
let blockNumber =
this.messenger.chainPrefix === 'hmy'
? data.params.result.Header.number
: data.params.result.number;
//patch fix (Header.number is undefined)
console.log(blockNumber)
if (!blockNumber) {
blockNumber = '0x0'
}
//end patch
this.emitTrack({
txHash,
attempt: this.confirmationCheck,
currentBlock: hexToNumber(blockNumber),
shardID,
});
...
Above is a patch for the transactionBase.ts that will allow contract transactions to continue.
Apply patch to here in transactionBase.ts:
I want to raise the flag here that I'm not sure the value of Header returned by the RPC data should have an undefined block number.
If it does sometimes return an undefined block number, let's handle this case.