Skip to content

Commit

Permalink
Fix TransactionResponse to have chainId instead of legacy networkId (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jan 11, 2020
1 parent 4151c0e commit 72b3bc9
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/providers/src.ts/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,28 +328,39 @@ export class Formatter {
}
*/

let result = Formatter.check(this.formats.transaction, transaction);
let result: TransactionResponse = Formatter.check(this.formats.transaction, transaction);

let networkId = transaction.networkId;
if (transaction.chainId != null) {
let chainId = transaction.chainId;

// geth-etc returns chainId
if (transaction.chainId != null && networkId == null && result.v == null) {
networkId = transaction.chainId;
}
if (isHexString(chainId)) {
chainId = BigNumber.from(chainId).toNumber();
}

if (isHexString(networkId)) {
networkId = BigNumber.from(networkId).toNumber();
}
result.chainId = chainId;

if (typeof(networkId) !== "number" && result.v != null) {
networkId = (result.v - 35) / 2;
if (networkId < 0) { networkId = 0; }
networkId = parseInt(networkId);
}
} else {
let chainId = transaction.networkId;

if (typeof(networkId) !== "number") { networkId = 0; }
// geth-etc returns chainId
if (chainId == null && result.v == null) {
chainId = transaction.chainId;
}

result.networkId = networkId;
if (isHexString(chainId)) {
chainId = BigNumber.from(chainId).toNumber();
}

if (typeof(chainId) !== "number" && result.v != null) {
chainId = (result.v - 35) / 2;
if (chainId < 0) { chainId = 0; }
chainId = parseInt(chainId);
}

if (typeof(chainId) !== "number") { chainId = 0; }

result.chainId = chainId;
}

// 0x0000... should actually be null
if (result.blockHash && result.blockHash.replace(/0/g, "") === "x") {
Expand Down

0 comments on commit 72b3bc9

Please sign in to comment.