|
|
@ -49,8 +49,8 @@ class Transaction { |
|
|
|
private data: string; |
|
|
|
private data: string; |
|
|
|
private value: BN; |
|
|
|
private value: BN; |
|
|
|
private chainId: number; |
|
|
|
private chainId: number; |
|
|
|
private txnHash: string; |
|
|
|
private rawTransaction: string; |
|
|
|
private unsignedTxnHash: string; |
|
|
|
private unsignedRawTransaction: string; |
|
|
|
private signature: Signature; |
|
|
|
private signature: Signature; |
|
|
|
|
|
|
|
|
|
|
|
// constructor
|
|
|
|
// constructor
|
|
|
@ -64,30 +64,36 @@ class Transaction { |
|
|
|
this.emitter = new Emitter(); |
|
|
|
this.emitter = new Emitter(); |
|
|
|
|
|
|
|
|
|
|
|
// intialize transaction
|
|
|
|
// intialize transaction
|
|
|
|
this.id = params ? params.id : '0x'; |
|
|
|
this.id = params && params.id ? params.id : '0x'; |
|
|
|
this.from = params ? params.from : '0x'; |
|
|
|
this.from = params && params.from ? params.from : '0x'; |
|
|
|
this.nonce = params ? params.nonce : 0; |
|
|
|
this.nonce = params && params.nonce ? params.nonce : 0; |
|
|
|
this.gasPrice = params ? params.gasPrice : new BN(0); |
|
|
|
this.gasPrice = params && params.gasPrice ? params.gasPrice : new BN(0); |
|
|
|
this.gasLimit = params ? params.gasLimit : new BN(0); |
|
|
|
this.gasLimit = params && params.gasLimit ? params.gasLimit : new BN(0); |
|
|
|
this.shardID = params ? params.shardID : 0; |
|
|
|
this.shardID = params && params.shardID ? params.shardID : 0; |
|
|
|
this.toShardID = params ? params.toShardID : 0; |
|
|
|
this.toShardID = params && params.toShardID ? params.toShardID : 0; |
|
|
|
|
|
|
|
|
|
|
|
this.to = params ? this.normalizeAddress(params.to) : '0x'; |
|
|
|
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x'; |
|
|
|
this.value = params ? params.value : new BN(0); |
|
|
|
this.value = params && params.value ? params.value : new BN(0); |
|
|
|
this.data = params ? params.data : '0x'; |
|
|
|
this.data = params && params.data ? params.data : '0x'; |
|
|
|
// chainid should change with different network settings
|
|
|
|
// chainid should change with different network settings
|
|
|
|
this.chainId = params ? params.chainId : this.messenger.chainId; |
|
|
|
this.chainId = |
|
|
|
this.txnHash = params ? params.txnHash : '0x'; |
|
|
|
params && params.chainId ? params.chainId : this.messenger.chainId; |
|
|
|
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x'; |
|
|
|
this.rawTransaction = |
|
|
|
this.signature = params |
|
|
|
params && params.rawTransaction ? params.rawTransaction : '0x'; |
|
|
|
? params.signature |
|
|
|
this.unsignedRawTransaction = |
|
|
|
: { |
|
|
|
params && params.unsignedRawTransaction |
|
|
|
r: '', |
|
|
|
? params.unsignedRawTransaction |
|
|
|
s: '', |
|
|
|
: '0x'; |
|
|
|
recoveryParam: 0, |
|
|
|
this.signature = |
|
|
|
v: 0, |
|
|
|
params && params.signature |
|
|
|
}; |
|
|
|
? params.signature |
|
|
|
this.receipt = params ? params.receipt : undefined; |
|
|
|
: { |
|
|
|
|
|
|
|
r: '', |
|
|
|
|
|
|
|
s: '', |
|
|
|
|
|
|
|
recoveryParam: 0, |
|
|
|
|
|
|
|
v: 0, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
this.receipt = params && params.receipt ? params.receipt : undefined; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
setMessenger(messenger: Messenger) { |
|
|
|
setMessenger(messenger: Messenger) { |
|
|
@ -159,12 +165,13 @@ class Transaction { |
|
|
|
return encode(raw); |
|
|
|
return encode(raw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
recover(txnHash: string): Transaction { |
|
|
|
recover(rawTransaction: string): Transaction { |
|
|
|
// temp setting to be compatible with eth
|
|
|
|
// temp setting to be compatible with eth
|
|
|
|
const recovered = |
|
|
|
const recovered = |
|
|
|
this.messenger.chainType === ChainType.Harmony |
|
|
|
this.messenger.chainType === ChainType.Harmony |
|
|
|
? recover(txnHash) |
|
|
|
? recover(rawTransaction) |
|
|
|
: recoverETH(txnHash); |
|
|
|
: recoverETH(rawTransaction); |
|
|
|
|
|
|
|
|
|
|
|
this.setParams(recovered); |
|
|
|
this.setParams(recovered); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -198,34 +205,39 @@ class Transaction { |
|
|
|
value: this.value || new BN(0), |
|
|
|
value: this.value || new BN(0), |
|
|
|
data: this.data || '0x', |
|
|
|
data: this.data || '0x', |
|
|
|
chainId: this.chainId || 0, |
|
|
|
chainId: this.chainId || 0, |
|
|
|
txnHash: this.txnHash || '0x', |
|
|
|
rawTransaction: this.rawTransaction || '0x', |
|
|
|
unsignedTxnHash: this.unsignedTxnHash || '0x', |
|
|
|
unsignedRawTransaction: this.unsignedRawTransaction || '0x', |
|
|
|
signature: this.signature || '0x', |
|
|
|
signature: this.signature || '0x', |
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
setParams(params: TxParams) { |
|
|
|
setParams(params: TxParams) { |
|
|
|
this.id = params ? params.id : '0x'; |
|
|
|
this.id = params && params.id ? params.id : '0x'; |
|
|
|
this.from = params ? params.from : '0x'; |
|
|
|
this.from = params && params.from ? params.from : '0x'; |
|
|
|
this.nonce = params ? params.nonce : 0; |
|
|
|
this.nonce = params && params.nonce ? params.nonce : 0; |
|
|
|
this.gasPrice = params ? params.gasPrice : new BN(0); |
|
|
|
this.gasPrice = params && params.gasPrice ? params.gasPrice : new BN(0); |
|
|
|
this.gasLimit = params ? params.gasLimit : new BN(0); |
|
|
|
this.gasLimit = params && params.gasLimit ? params.gasLimit : new BN(0); |
|
|
|
this.shardID = params ? params.shardID : 0; |
|
|
|
this.shardID = params && params.shardID ? params.shardID : 0; |
|
|
|
this.toShardID = params ? params.toShardID : 0; |
|
|
|
this.toShardID = params && params.toShardID ? params.toShardID : 0; |
|
|
|
this.to = params ? this.normalizeAddress(params.to) : '0x'; |
|
|
|
this.to = params && params.to ? this.normalizeAddress(params.to) : '0x'; |
|
|
|
this.value = params ? params.value : new BN(0); |
|
|
|
this.value = params && params.value ? params.value : new BN(0); |
|
|
|
this.data = params ? params.data : '0x'; |
|
|
|
this.data = params && params.data ? params.data : '0x'; |
|
|
|
this.chainId = params ? params.chainId : 0; |
|
|
|
this.chainId = params && params.chainId ? params.chainId : 0; |
|
|
|
this.txnHash = params ? params.txnHash : '0x'; |
|
|
|
this.rawTransaction = |
|
|
|
this.unsignedTxnHash = params ? params.unsignedTxnHash : '0x'; |
|
|
|
params && params.rawTransaction ? params.rawTransaction : '0x'; |
|
|
|
this.signature = params |
|
|
|
this.unsignedRawTransaction = |
|
|
|
? params.signature |
|
|
|
params && params.unsignedRawTransaction |
|
|
|
: { |
|
|
|
? params.unsignedRawTransaction |
|
|
|
r: '', |
|
|
|
: '0x'; |
|
|
|
s: '', |
|
|
|
this.signature = |
|
|
|
recoveryParam: 0, |
|
|
|
params && params.signature |
|
|
|
v: 0, |
|
|
|
? params.signature |
|
|
|
}; |
|
|
|
: { |
|
|
|
if (this.txnHash !== '0x') { |
|
|
|
r: '', |
|
|
|
|
|
|
|
s: '', |
|
|
|
|
|
|
|
recoveryParam: 0, |
|
|
|
|
|
|
|
v: 0, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
if (this.rawTransaction !== '0x') { |
|
|
|
this.setTxStatus(TxStatus.SIGNED); |
|
|
|
this.setTxStatus(TxStatus.SIGNED); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.setTxStatus(TxStatus.INTIALIZED); |
|
|
|
this.setTxStatus(TxStatus.INTIALIZED); |
|
|
@ -270,7 +282,7 @@ class Transaction { |
|
|
|
|
|
|
|
|
|
|
|
async sendTransaction(): Promise<[Transaction, string]> { |
|
|
|
async sendTransaction(): Promise<[Transaction, string]> { |
|
|
|
// TODO: we use eth RPC setting for now, incase we have other params, we should add here
|
|
|
|
// TODO: we use eth RPC setting for now, incase we have other params, we should add here
|
|
|
|
if (this.txnHash === 'tx' || this.txnHash === undefined) { |
|
|
|
if (this.rawTransaction === 'tx' || this.rawTransaction === undefined) { |
|
|
|
throw new Error('Transaction not signed'); |
|
|
|
throw new Error('Transaction not signed'); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!this.messenger) { |
|
|
|
if (!this.messenger) { |
|
|
@ -278,7 +290,7 @@ class Transaction { |
|
|
|
} |
|
|
|
} |
|
|
|
const res = await this.messenger.send( |
|
|
|
const res = await this.messenger.send( |
|
|
|
RPCMethod.SendRawTransaction, |
|
|
|
RPCMethod.SendRawTransaction, |
|
|
|
this.txnHash, |
|
|
|
this.rawTransaction, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// temporarilly hard coded
|
|
|
|
// temporarilly hard coded
|
|
|
|