Skip to content

Commit

Permalink
Fix receipt log handling in arb-provider-ethers and arb-provider-ethers
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalodner committed Sep 7, 2019
1 parent 5a5d2c2 commit fdcdfab
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
33 changes: 19 additions & 14 deletions packages/arb-provider-ethers/src/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,19 @@ export enum EVMCode {
BadSequenceCode = 4,
}

interface Log {
contractId: ethers.utils.BigNumber;
data: Uint8Array;
topics: ethers.utils.BigNumber[];
}

function logValToLog(val: ArbValue.Value): Log {
function logValToLog(val: ArbValue.Value, index: number, orig: OrigMessage): ethers.providers.Log {
const value = val as ArbValue.TupleValue;
return {
contractId: (value.get(0) as ArbValue.IntValue).bignum,
data: ArbValue.sizedByteRangeToBytes(value.get(1) as ArbValue.TupleValue),
topics: value.contents.slice(2).map(rawTopic => (rawTopic as ArbValue.IntValue).bignum),
blockNumber: orig.blockHeight.toNumber(),
blockHash: orig.txHash,
transactionIndex: 0,
removed: false,
transactionLogIndex: index,
address: ethers.utils.hexlify((value.get(0) as ArbValue.IntValue).bignum),
data: ethers.utils.hexlify(ArbValue.sizedByteRangeToBytes(value.get(1) as ArbValue.TupleValue)),
topics: value.contents.slice(2).map(rawTopic => ethers.utils.hexlify((rawTopic as ArbValue.IntValue).bignum)),
transactionHash: orig.txHash,
logIndex: index,
};
}

Expand Down Expand Up @@ -88,13 +89,15 @@ export type EVMResult = EVMReturn | EVMRevert | EVMStop | EVMBadSequenceCode | E
export class EVMReturn {
public orig: OrigMessage;
public data: Uint8Array;
public logs: Log[];
public logs: ethers.providers.Log[];
public returnType: EVMCode.Return;

constructor(value: ArbValue.TupleValue) {
this.orig = new OrigMessage(value.get(0) as ArbValue.TupleValue);
this.data = ArbValue.sizedByteRangeToBytes(value.get(2) as ArbValue.TupleValue);
this.logs = stackValueToList(value.get(1) as ArbValue.TupleValue).map(logValToLog);
this.logs = stackValueToList(value.get(1) as ArbValue.TupleValue).map((val, index) => {
return logValToLog(val, index, this.orig);
});
this.returnType = EVMCode.Return;
}
}
Expand All @@ -113,12 +116,14 @@ export class EVMRevert {

export class EVMStop {
public orig: OrigMessage;
public logs: Log[];
public logs: ethers.providers.Log[];
public returnType: EVMCode.Stop;

constructor(value: ArbValue.TupleValue) {
this.orig = new OrigMessage(value.get(0) as ArbValue.TupleValue);
this.logs = stackValueToList(value.get(1) as ArbValue.TupleValue).map(logValToLog);
this.logs = stackValueToList(value.get(1) as ArbValue.TupleValue).map((val, index) => {
return logValToLog(val, index, this.orig);
});
this.returnType = EVMCode.Stop;
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/arb-provider-ethers/src/lib/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,10 @@ export class ArbProvider extends ethers.providers.BaseProvider {
const result = await this.getMessageResult(params.transactionHash);
if (result) {
let status = 0;
let logs: ethers.providers.Log[] = [];
if (result.evmVal.returnType === EVMCode.Return || result.evmVal.returnType === EVMCode.Stop) {
status = 1;
logs = result.evmVal.logs;
}
return {
blockHash: result.txHash,
Expand All @@ -212,7 +214,7 @@ export class ArbProvider extends ethers.providers.BaseProvider {
cumulativeGasUsed: ethers.utils.bigNumberify(1),
from: result.evmVal.orig.caller,
gasUsed: ethers.utils.bigNumberify(1),
logs: [],
logs,
status,
to: result.evmVal.orig.contractID,
transactionHash: result.txHash,
Expand Down
7 changes: 1 addition & 6 deletions packages/arb-provider-web3/ethers-web3-bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,7 @@ function formatReceipt(receipt) {
true
);

fillCopy(
receipt,
log,
["address", "blockHash", "data", "transactionHash"],
true
);
fillCopy(receipt, log, ["blockHash", "transactionHash"], true);
});

return result;
Expand Down

0 comments on commit fdcdfab

Please sign in to comment.