-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EIP1559 + EIP2718 support #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,15 @@ const EthObject = require('./ethObject') | |
class Transaction extends EthObject{ | ||
|
||
static get fields(){ return [ | ||
'chainId', | ||
'nonce', | ||
'gasPrice', | ||
'maxPriorityFeePerGas', | ||
'maxFeePerGas', | ||
'gasLimit', | ||
'to', | ||
'value', | ||
'data', | ||
'accessList', | ||
'v', | ||
'r', | ||
's', | ||
Comment on lines
6
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is a problem here because these new fields knock the ordering off when generating objects that dont include them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ran this code on proofs using eth mainnet which has a collection of legacy/version 1/version 2 transactions, it does create properly, can you give example where it would break?
Comment on lines
+7
to
18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you'll need to have some conditionals here for backwards compatibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it only encode fields that are set in the object and skips over the ones that aren't? The proofs are valid across all the tx types. |
||
|
@@ -18,23 +21,95 @@ class Transaction extends EthObject{ | |
constructor(raw = Transaction.NULL){ | ||
super(Transaction.fields, raw) | ||
} | ||
static fromBuffer(buf){ | ||
if(buf) { | ||
// marker for EIP2718 TX Envelope type - anything under is type followed by RLP, over is standard RLP | ||
if(buf[0] > 0x7f) { | ||
return new Transaction(decode(buf)) | ||
} else { | ||
let tx = new Transaction(decode(buf.slice(1))) | ||
tx.objtype = toBuffer(buf[0]) | ||
return tx | ||
} | ||
} else { | ||
return new Transaction() | ||
} | ||
} | ||
|
||
static fromBuffer(buf){ return buf ? new Transaction(decode(buf)) : new Transaction() } | ||
static fromHex(hex){ return hex ? new Transaction(decode(hex)) : new Transaction() } | ||
static fromHex(hex){ | ||
return this.fromBuffer(toBuffer(hex)) | ||
} | ||
static fromRaw(raw){ return new Transaction(raw) } | ||
static fromObject(rpcResult){ return Transaction.fromRpc(rpcResult) } | ||
static fromRpc(rpcResult){ | ||
return new Transaction([ | ||
toBuffer(rpcResult.nonce), | ||
toBuffer(rpcResult.gasPrice), | ||
toBuffer(rpcResult.gas || rpcResult.gasLimit), | ||
toBuffer(rpcResult.to), | ||
toBuffer(rpcResult.value), | ||
toBuffer(rpcResult.input || rpcResult.data), | ||
toBuffer(rpcResult.v), | ||
toBuffer(rpcResult.r), | ||
toBuffer(rpcResult.s) | ||
]) | ||
// see definitions: https://eips.ethereum.org/EIPS/eip-1559 | ||
// https://eips.ethereum.org/EIPS/eip-2718 1559-payload | ||
if(rpcResult.type == "0x2") { | ||
let accessList = [] | ||
for (var i = 0; i < rpcResult.accessList.length; i++) { | ||
var listObjAtIndex = rpcResult.accessList[i] | ||
var storageKeys = [] | ||
for (var j = 0; j < listObjAtIndex.storageKeys.length; j++) { | ||
storageKeys.push(toBuffer(listObjAtIndex.storageKeys[j])) | ||
} | ||
accessList.push([toBuffer(listObjAtIndex.address), storageKeys]) | ||
} | ||
let tx = new Transaction([ | ||
toBuffer(rpcResult.chainId), | ||
toBuffer(rpcResult.nonce), | ||
toBuffer(rpcResult.maxPriorityFeePerGas), | ||
toBuffer(rpcResult.maxFeePerGas), | ||
toBuffer(rpcResult.gas || rpcResult.gasLimit), | ||
toBuffer(rpcResult.to), | ||
toBuffer(rpcResult.value), | ||
toBuffer(rpcResult.input || rpcResult.data), | ||
accessList, | ||
toBuffer(rpcResult.v), | ||
toBuffer(rpcResult.r), | ||
toBuffer(rpcResult.s) | ||
]) | ||
tx.objtype = toBuffer(rpcResult.type) | ||
return tx | ||
// https://eips.ethereum.org/EIPS/eip-2718 2930-payload | ||
} else if(rpcResult.type == "0x1") { | ||
let accessList = [] | ||
for (var i = 0; i < rpcResult.accessList.length; i++) { | ||
var listObjAtIndex = rpcResult.accessList[i] | ||
var storageKeys = [] | ||
for (var j = 0; j < listObjAtIndex.storageKeys.length; j++) { | ||
storageKeys.push(toBuffer(listObjAtIndex.storageKeys[j])) | ||
} | ||
accessList.push([toBuffer(listObjAtIndex.address), storageKeys]) | ||
} | ||
let tx = new Transaction([ | ||
toBuffer(rpcResult.chainId), | ||
toBuffer(rpcResult.nonce), | ||
toBuffer(rpcResult.gasPrice), | ||
toBuffer(rpcResult.gas || rpcResult.gasLimit), | ||
toBuffer(rpcResult.to), | ||
toBuffer(rpcResult.value), | ||
toBuffer(rpcResult.input || rpcResult.data), | ||
accessList, | ||
toBuffer(rpcResult.v), | ||
toBuffer(rpcResult.r), | ||
toBuffer(rpcResult.s) | ||
]) | ||
tx.objtype = toBuffer(rpcResult.type) | ||
return tx | ||
} | ||
else { | ||
return new Transaction([ | ||
toBuffer(rpcResult.nonce), | ||
toBuffer(rpcResult.gasPrice), | ||
toBuffer(rpcResult.gas || rpcResult.gasLimit), | ||
toBuffer(rpcResult.to), | ||
toBuffer(rpcResult.value), | ||
toBuffer(rpcResult.input || rpcResult.data), | ||
toBuffer(rpcResult.v), | ||
toBuffer(rpcResult.r), | ||
toBuffer(rpcResult.s) | ||
]) | ||
} | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good here