fix(transaction): getTransactionReceipt if no status but root returns

dev
neeboo 5 years ago
parent ea9d15d8e0
commit 1efc230e73
  1. 17
      packages/harmony-transaction/src/transaction.ts
  2. 6
      packages/harmony-transaction/src/types.ts
  3. 23
      packages/harmony-transaction/src/utils.ts

@ -43,7 +43,7 @@ class Transaction {
private nonce: number | string;
private to: string;
private shardID: number | string;
private toShardID: number | string;
// private toShardID: number | string;
private gasLimit: BN;
private gasPrice: BN;
private data: string;
@ -70,9 +70,8 @@ class Transaction {
this.gasPrice = params ? params.gasPrice : new BN(0);
this.gasLimit = params ? params.gasLimit : new BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
// this.toShardID = params ? params.toShardID : 0;
// this.to= params ? params.to:'0x';
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new BN(0);
this.data = params ? params.data : '0x';
@ -175,7 +174,7 @@ class Transaction {
from: this.txParams.from || '0x',
to: this.txParams.to || '0x',
shardID: this.txParams.shardID ? numberToHex(this.shardID) : '0x',
toShardID: this.txParams.toShardID ? numberToHex(this.toShardID) : '0x',
// toShardID: this.txParams.toShardID ? numberToHex(this.toShardID) : '0x',
gas: this.txParams.gasLimit ? numberToHex(this.txParams.gasLimit) : '0x',
gasPrice: this.txParams.gasPrice
? numberToHex(this.txParams.gasPrice)
@ -194,7 +193,7 @@ class Transaction {
gasPrice: this.gasPrice || new BN(0),
gasLimit: this.gasLimit || new BN(0),
shardID: this.shardID || 0,
toShardID: this.toShardID || 0,
// toShardID: this.toShardID || 0,
to: this.normalizeAddress(this.to) || '0x',
value: this.value || new BN(0),
data: this.data || '0x',
@ -211,8 +210,7 @@ class Transaction {
this.gasPrice = params ? params.gasPrice : new BN(0);
this.gasLimit = params ? params.gasLimit : new BN(0);
this.shardID = params ? params.shardID : 0;
this.toShardID = params ? params.toShardID : 0;
// this.to = params ? params.to : '0x';
// this.toShardID = params ? params.toShardID : 0;
this.to = params ? this.normalizeAddress(params.to) : '0x';
this.value = params ? params.value : new BN(0);
this.data = params ? params.data : '0x';
@ -314,9 +312,14 @@ class Transaction {
if (this.receipt) {
if (this.receipt.status && this.receipt.status === '0x1') {
this.receipt.byzantium = true;
this.txStatus = TxStatus.CONFIRMED;
} else if (this.receipt.status && this.receipt.status === '0x0') {
this.receipt.byzantium = true;
this.txStatus = TxStatus.REJECTED;
} else if (this.receipt.status === undefined && this.receipt.root) {
this.receipt.byzantium = false;
this.txStatus = TxStatus.CONFIRMED;
}
return true;
} else {

@ -7,7 +7,7 @@ export interface TxParams {
gasLimit: BN;
gasPrice: BN;
shardID: number | string;
toShardID: number | string;
// toShardID: number | string;
data: string;
value: BN;
chainId: number;
@ -36,10 +36,12 @@ export interface TransasctionReceipt {
cumulativeGasUsed: string; // 13244
contractAddress?: string | null; // or null, if none was created
logs: any[];
status: string;
logsBloom: string; // 256 byte bloom filter
v: string;
r: string;
s: string;
responseType?: string;
byzantium?: boolean;
status?: string; // post Byzantium will return `0x0` or `0x1`
root?: string; // pre Byzantium will return `root`
}

@ -25,7 +25,8 @@ export const transactionFields = [
{ name: 'gasPrice', length: 32, fix: false, transform: 'hex' },
{ name: 'gasLimit', length: 32, fix: false, transform: 'hex' },
{ name: 'shardID', length: 16, fix: false },
{ name: 'toShardID', length: 16, fix: false },
// recover it after main repo fix
// { name: 'toShardID', length: 16, fix: false },
{ name: 'to', length: 20, fix: true },
{ name: 'value', length: 32, fix: false, transform: 'hex' },
{ name: 'data', fix: false },
@ -62,7 +63,7 @@ export const handleAddress = (value: string): string => {
export const recover = (rawTransaction: string) => {
const transaction = decode(rawTransaction);
if (transaction.length !== 11 && transaction.length !== 8) {
if (transaction.length !== 10 && transaction.length !== 7) {
throw new Error('invalid rawTransaction');
}
@ -75,10 +76,10 @@ export const recover = (rawTransaction: string) => {
gasPrice: new BN(strip0x(handleNumber(transaction[1]))),
gasLimit: new BN(strip0x(handleNumber(transaction[2]))),
shardID: new BN(strip0x(handleNumber(transaction[3]))).toNumber(),
toShardID: new BN(strip0x(handleNumber(transaction[4]))).toNumber(),
to: handleAddress(transaction[5]),
value: new BN(strip0x(handleNumber(transaction[6]))),
data: transaction[7],
// toShardID: new BN(strip0x(handleNumber(transaction[4]))).toNumber(),
to: handleAddress(transaction[4]),
value: new BN(strip0x(handleNumber(transaction[5]))),
data: transaction[6],
chainId: 0,
signature: {
r: '',
@ -89,19 +90,19 @@ export const recover = (rawTransaction: string) => {
};
// Legacy unsigned transaction
if (transaction.length === 8) {
if (transaction.length === 7) {
tx.unsignedTxnHash = rawTransaction;
return tx;
}
try {
tx.signature.v = new BN(strip0x(handleNumber(transaction[8]))).toNumber();
tx.signature.v = new BN(strip0x(handleNumber(transaction[7]))).toNumber();
} catch (error) {
throw error;
}
tx.signature.r = hexZeroPad(transaction[9], 32);
tx.signature.s = hexZeroPad(transaction[10], 32);
tx.signature.r = hexZeroPad(transaction[8], 32);
tx.signature.s = hexZeroPad(transaction[9], 32);
if (
new BN(strip0x(handleNumber(tx.signature.r))).isZero() &&
@ -161,7 +162,7 @@ export const recoverETH = (rawTransaction: string) => {
gasPrice: new BN(strip0x(handleNumber(transaction[1]))),
gasLimit: new BN(strip0x(handleNumber(transaction[2]))),
shardID: 0,
toShardID: 0,
// toShardID: 0,
to: handleAddress(transaction[3]),
value: new BN(strip0x(handleNumber(transaction[4]))),
data: transaction[5],

Loading…
Cancel
Save