chore(hdnode):fix signTransaction with chainId and truffleProvider with chainId

staking
neeboo 5 years ago
parent 504f5416d2
commit d4c82f0ef2
  1. 16
      packages/harmony-account/src/hdnode.ts
  2. 14
      packages/harmony-core/src/truffleProvider.ts

@ -49,8 +49,7 @@ export class HDNode {
public provider: HttpProvider | WSProvider; public provider: HttpProvider | WSProvider;
public gasLimit: string; public gasLimit: string;
public gasPrice: string; public gasPrice: string;
public messenger: Messenger;
private messenger: Messenger;
private shardID: number; private shardID: number;
private hdwallet: hdkey | undefined; private hdwallet: hdkey | undefined;
private path: string; private path: string;
@ -202,7 +201,18 @@ export class HDNode {
const signerAccount = new Account(prv, this.messenger); const signerAccount = new Account(prv, this.messenger);
const tx = new Transaction( const tx = new Transaction(
{ ...txParams, from, to, gasLimit, gasPrice, value, nonce, data, shardID: this.shardID }, {
...txParams,
from,
to,
gasLimit,
gasPrice,
value,
nonce,
data,
shardID: this.shardID,
chainId: this.messenger.chainId,
},
this.messenger, this.messenger,
TxStatus.INTIALIZED, TxStatus.INTIALIZED,
); );

@ -63,6 +63,7 @@ export class TruffleProvider extends HDNode {
} }
async send(...args: [RPCRequestPayload<any>, any]) { async send(...args: [RPCRequestPayload<any>, any]) {
const { newArgs, id, params, newMethod, callback } = this.resolveArgs(...args); const { newArgs, id, params, newMethod, callback } = this.resolveArgs(...args);
console.log({ newMethod, newArgs, id, params });
switch (newMethod) { switch (newMethod) {
case 'hmy_accounts': { case 'hmy_accounts': {
const accounts = this.getAccounts(); const accounts = this.getAccounts();
@ -120,6 +121,18 @@ export class TruffleProvider extends HDNode {
); );
return this.resolveResult(result); return this.resolveResult(result);
} }
case 'net_version': {
callback(null, {
result: String(this.messenger.chainId),
id,
jsonrpc: '2.0',
});
return {
result: String(this.messenger.chainId),
id,
jsonrpc: '2.0',
};
}
case 'hmy_getBlockByNumber': { case 'hmy_getBlockByNumber': {
const result = await this.provider.send(newArgs, (err: any, res: any) => { const result = await this.provider.send(newArgs, (err: any, res: any) => {
try { try {
@ -149,6 +162,7 @@ export class TruffleProvider extends HDNode {
default: { default: {
// hmy_getBlockByNumber // hmy_getBlockByNumber
const result = await this.provider.send( const result = await this.provider.send(
newArgs, newArgs,
(err: any, res: ResponseMiddleware | any) => this.resolveCallback(err, res, callback), (err: any, res: ResponseMiddleware | any) => this.resolveCallback(err, res, callback),

Loading…
Cancel
Save