Skip to content

Commit

Permalink
feat: Implement EIP-1559 JSON-RPC (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioAnongba authored Sep 15, 2021
1 parent 6e57294 commit 4f9aa1d
Show file tree
Hide file tree
Showing 17 changed files with 559 additions and 369 deletions.
9 changes: 6 additions & 3 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ func newMigrateCommand() *cobra.Command {
},
}

flags.LoggerFlags(migrateCmd.Flags())
flags.PGFlags(migrateCmd.Flags())

// Register Up command
upCmd := &cobra.Command{
Use: "up [target]",
Expand All @@ -42,6 +39,8 @@ func newMigrateCommand() *cobra.Command {
},
}
migrateCmd.AddCommand(upCmd)
flags.LoggerFlags(upCmd.Flags())
flags.PGFlags(upCmd.Flags())

// Register Down command
downCmd := &cobra.Command{
Expand All @@ -52,6 +51,8 @@ func newMigrateCommand() *cobra.Command {
},
}
migrateCmd.AddCommand(downCmd)
flags.LoggerFlags(downCmd.Flags())
flags.PGFlags(downCmd.Flags())

// Register Reset command
resetCmd := &cobra.Command{
Expand All @@ -62,6 +63,8 @@ func newMigrateCommand() *cobra.Command {
},
}
migrateCmd.AddCommand(resetCmd)
flags.LoggerFlags(resetCmd.Flags())
flags.PGFlags(resetCmd.Flags())

return migrateCmd
}
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.7.0
github.com/swaggo/swag v1.7.1
go.elastic.co/ecszap v1.0.0
go.uber.org/atomic v1.8.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
Expand Down
20 changes: 20 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ClickHouse/clickhouse-go v1.3.12/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/Microsoft/go-winio v0.4.15-0.20190919025122-fc70bd9a86b5/go.mod h1:tTuCMEN+UleMWgg9dVx4Hu52b1bJo+59jBh3ajtinzw=
github.com/Microsoft/go-winio v0.4.16 h1:FtSW/jqD+l4ba5iPBj9CODVtgfYAD8w2wS923g/cFDk=
github.com/Microsoft/go-winio v0.4.16/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
Expand Down Expand Up @@ -259,12 +263,19 @@ github.com/go-ole/go-ole v1.2.1 h1:2lOsA72HgjxAuMlKpFiCbHTvu44PIVkZ5hqm3RSdI/E=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL98+wF9xc8zWvFonSJ8=
github.com/go-openapi/jsonreference v0.19.5 h1:1WJP/wi4OjB4iV8KVbH73rQaoialJrqv8gitZLxGLtM=
github.com/go-openapi/jsonreference v0.19.5/go.mod h1:RdybgQwPxbL4UEjuAruzK1x3nE69AqPYEJeo/TWfEeg=
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
github.com/go-openapi/spec v0.20.3 h1:uH9RQ6vdyPSs2pSy9fL8QPspDF2AMIMPtmK5coSSjtQ=
github.com/go-openapi/spec v0.20.3/go.mod h1:gG4F8wdEDN+YPBMVnzE85Rbhf+Th2DTvA9nFPQ5AYEg=
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.14 h1:gm3vOOXfiuw5i9p5N9xJvfjvuofpyvLA9Wr6QfK5Fng=
github.com/go-openapi/swag v0.19.14/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/go-pg/pg/v10 v10.10.1 h1:82lLX4KGs2wOFOvVVIICoU0Si1fLu6Aitniu73HaDuM=
github.com/go-pg/pg/v10 v10.10.1/go.mod h1:EmoJGYErc+stNN/1Jf+o4csXuprjxcRztBnn6cHe38E=
github.com/go-pg/zerochecker v0.2.0 h1:pp7f72c3DobMWOb2ErtZsnrPaSvHd2W4o9//8HtF4mU=
Expand Down Expand Up @@ -493,6 +504,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand Down Expand Up @@ -553,6 +566,8 @@ github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzR
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/markbates/pkger v0.15.1/go.mod h1:0JoVlrol20BSywW79rN3kdFFsE5xYM+rSCQDXbLhiuI=
github.com/matryer/moq v0.0.0-20190312154309-6cfb0558e1bd/go.mod h1:9ELz6aaclSIGnZBoaSLZ3NAl1VTufbOrXBPvtcy6WiQ=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
Expand Down Expand Up @@ -751,6 +766,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/swaggo/swag v1.7.1 h1:gY9ZakXlNWg/i/v5bQBic7VMZ4teq4m89lpiao74p/s=
github.com/swaggo/swag v1.7.1/go.mod h1:gAiHxNTb9cIpNmA/VEGUP+CyZMCP/EW7mdtc8Bny+p8=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 h1:xQdMZ1WLrgkkvOZ/LDQxjVxMLdby7osSh4ZEVa5sIjs=
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954/go.mod h1:u2MKkTVTVJWe5D1rCvame8WqhBd88EuIwODJZ1VHCPM=
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
Expand Down Expand Up @@ -870,6 +887,7 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1076,6 +1094,7 @@ golang.org/x/tools v0.0.0-20200814230902-9882f1d1823d/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200817023811-d00afeaade8f/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200818005847-188abfa75333/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down Expand Up @@ -1213,6 +1232,7 @@ gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
Expand Down
100 changes: 68 additions & 32 deletions pkg/ethereum/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,56 @@ func (args *PrivateArgs) WithPrivacyGroupID(id string) *PrivateArgs {

// TODO: Delete usage of unnecessary pointers: https://app.zenhub.com/workspaces/orchestrate-5ea70772b186e10067f57842/issues/consensys/quorum-key-manager/96
type SendTxMsg struct {
From ethcommon.Address
To *ethcommon.Address
Gas *uint64
GasPrice *big.Int
Value *big.Int
Nonce *uint64
Data *[]byte
From ethcommon.Address
To *ethcommon.Address
Gas *uint64
GasPrice *big.Int
Value *big.Int
Nonce *uint64
Data *[]byte
GasFeeCap *big.Int
GasTipCap *big.Int
AccessList types.AccessList

PrivateArgs
}

func (msg *SendTxMsg) IsPrivate() bool {
return msg.PrivateArgs != PrivateArgs{}
}

func (msg *SendTxMsg) TxData() *types.Transaction {
if msg.To == nil {
return types.NewContractCreation(*msg.Nonce, msg.Value, *msg.Gas, msg.GasPrice, *msg.Data)
return msg.PrivateArgs != PrivateArgs{} && msg.PrivateArgs.PrivateFrom != nil
}

func (msg *SendTxMsg) IsLegacy() bool {
return msg.GasPrice != nil
}

func (msg *SendTxMsg) TxData(txType int, chainID *big.Int) *types.Transaction {
var txData types.TxData

switch txType {
case types.LegacyTxType:
txData = &types.LegacyTx{
Nonce: *msg.Nonce,
GasPrice: msg.GasPrice,
Gas: *msg.Gas,
To: msg.To,
Value: msg.Value,
Data: *msg.Data,
}
case types.DynamicFeeTxType:
txData = &types.DynamicFeeTx{
ChainID: chainID,
Nonce: *msg.Nonce,
GasTipCap: msg.GasTipCap,
GasFeeCap: msg.GasFeeCap,
Gas: *msg.Gas,
To: msg.To,
Value: msg.Value,
Data: *msg.Data,
AccessList: msg.AccessList,
}
}

return types.NewTransaction(*msg.Nonce, *msg.To, msg.Value, *msg.Gas, msg.GasPrice, *msg.Data)
return types.NewTx(txData)
}

// TODO: Delete this function and use only go-quorum types when
Expand All @@ -95,14 +124,17 @@ func (msg *SendTxMsg) TxDataQuorum() *quorumtypes.Transaction {

// TODO: Delete usage of unnecessary pointers: https://app.zenhub.com/workspaces/orchestrate-5ea70772b186e10067f57842/issues/consensys/quorum-key-manager/96
type jsonSendTxMsg struct {
From ethcommon.Address `json:"from,omitempty"`
To *ethcommon.Address `json:"to,omitempty"`
Gas *hexutil.Uint64 `json:"gas,omitempty"`
GasPrice *hexutil.Big `json:"gasPrice,omitempty"`
Value *hexutil.Big `json:"value,omitempty"`
Nonce *hexutil.Uint64 `json:"nonce,omitempty"`
Data *hexutil.Bytes `json:"data,omitempty"`
Input *hexutil.Bytes `json:"input,omitempty"`
From ethcommon.Address `json:"from,omitempty"`
To *ethcommon.Address `json:"to,omitempty"`
Gas *hexutil.Uint64 `json:"gas,omitempty"`
GasPrice *hexutil.Big `json:"gasPrice,omitempty"`
Value *hexutil.Big `json:"value,omitempty"`
Nonce *hexutil.Uint64 `json:"nonce,omitempty"`
Data *hexutil.Bytes `json:"data,omitempty"`
Input *hexutil.Bytes `json:"input,omitempty"`
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
AccessList types.AccessList `json:"accessList,omitempty"`

PrivateArgs
}
Expand All @@ -123,6 +155,9 @@ func (msg *SendTxMsg) UnmarshalJSON(b []byte) error {
Nonce: (*uint64)(raw.Nonce),
PrivateArgs: raw.PrivateArgs,
Data: (*[]byte)(raw.Input),
GasTipCap: (*big.Int)(raw.GasTipCap),
GasFeeCap: (*big.Int)(raw.GasFeeCap),
AccessList: raw.AccessList,
}

if raw.Data != nil {
Expand All @@ -141,6 +176,9 @@ func (msg *SendTxMsg) MarshalJSON() ([]byte, error) {
Value: (*hexutil.Big)(msg.Value),
Nonce: (*hexutil.Uint64)(msg.Nonce),
Data: (*hexutil.Bytes)(msg.Data),
GasTipCap: (*hexutil.Big)(msg.GasTipCap),
GasFeeCap: (*hexutil.Big)(msg.GasFeeCap),
AccessList: msg.AccessList,
PrivateArgs: msg.PrivateArgs,
})
}
Expand All @@ -159,20 +197,18 @@ type SendEEATxMsg struct {

func (msg *SendEEATxMsg) TxData() *types.Transaction {
var data []byte
var nonce uint64
if msg.Data != nil {
data = *msg.Data
}

if msg.Nonce != nil {
nonce = *msg.Nonce
}

if msg.To == nil {
return types.NewContractCreation(nonce, nil, 0, nil, data)
}

return types.NewTransaction(nonce, *msg.To, nil, *msg.Gas, msg.GasPrice, data)
return types.NewTx(&types.LegacyTx{
Nonce: *msg.Nonce,
GasPrice: msg.GasPrice,
Gas: *msg.Gas,
To: msg.To,
Value: nil,
Data: data,
})
}

// TODO: Delete usage of unnecessary pointers: https://app.zenhub.com/workspaces/orchestrate-5ea70772b186e10067f57842/issues/consensys/quorum-key-manager/96
Expand Down
62 changes: 38 additions & 24 deletions pkg/ethereum/call_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ import (
"encoding/json"
"math/big"

"github.com/ethereum/go-ethereum/core/types"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
)

// CallMsg contains parameters for contract calls.
type CallMsg struct {
From *ethcommon.Address // the sender of the 'transaction'
To *ethcommon.Address // the destination contract (nil for contract creation)
Gas *uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call
Data *[]byte // input data, usually an ABI-encoded contract method invocation
From *ethcommon.Address // the sender of the 'transaction'
To *ethcommon.Address // the destination contract (nil for contract creation)
Gas *uint64 // if 0, the call executes with near-infinite gas
GasPrice *big.Int // wei <-> gas exchange ratio
Value *big.Int // amount of wei sent along with the call
Data *[]byte // input data, usually an ABI-encoded contract method invocation
GasFeeCap *big.Int
GasTipCap *big.Int
AccessList types.AccessList
}

func (msg *CallMsg) WithFrom(addr ethcommon.Address) *CallMsg {
Expand Down Expand Up @@ -53,12 +58,15 @@ func (msg *CallMsg) WithData(d []byte) *CallMsg {
}

type jsonCallMsg struct {
From *ethcommon.Address `json:"from,omitempty"`
To *ethcommon.Address `json:"to,omitempty"`
Gas *hexutil.Uint64 `json:"gas,omitempty"`
GasPrice *hexutil.Big `json:"gasPrice,omitempty"`
Value *hexutil.Big `json:"value,omitempty"`
Data *hexutil.Bytes `json:"data,omitempty"`
From *ethcommon.Address `json:"from,omitempty"`
To *ethcommon.Address `json:"to,omitempty"`
Gas *hexutil.Uint64 `json:"gas,omitempty"`
GasPrice *hexutil.Big `json:"gasPrice,omitempty"`
Value *hexutil.Big `json:"value,omitempty"`
Data *hexutil.Bytes `json:"data,omitempty"`
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
GasTipCap *hexutil.Big `json:"maxPriorityFeePerGas,omitempty"`
AccessList types.AccessList `json:"accessList,omitempty"`
}

func (msg *CallMsg) UnmarshalJSON(b []byte) error {
Expand All @@ -69,12 +77,15 @@ func (msg *CallMsg) UnmarshalJSON(b []byte) error {
}

*msg = CallMsg{
From: raw.From,
To: raw.To,
Gas: (*uint64)(raw.Gas),
GasPrice: (*big.Int)(raw.GasPrice),
Value: (*big.Int)(raw.Value),
Data: (*[]byte)(raw.Data),
From: raw.From,
To: raw.To,
Gas: (*uint64)(raw.Gas),
GasPrice: (*big.Int)(raw.GasPrice),
Value: (*big.Int)(raw.Value),
Data: (*[]byte)(raw.Data),
GasTipCap: (*big.Int)(raw.GasTipCap),
GasFeeCap: (*big.Int)(raw.GasFeeCap),
AccessList: raw.AccessList,
}

if raw.Data != nil {
Expand All @@ -86,11 +97,14 @@ func (msg *CallMsg) UnmarshalJSON(b []byte) error {

func (msg *CallMsg) MarshalJSON() ([]byte, error) {
return json.Marshal(&jsonCallMsg{
From: msg.From,
To: msg.To,
Gas: (*hexutil.Uint64)(msg.Gas),
GasPrice: (*hexutil.Big)(msg.GasPrice),
Value: (*hexutil.Big)(msg.Value),
Data: (*hexutil.Bytes)(msg.Data),
From: msg.From,
To: msg.To,
Gas: (*hexutil.Uint64)(msg.Gas),
GasPrice: (*hexutil.Big)(msg.GasPrice),
Value: (*hexutil.Big)(msg.Value),
Data: (*hexutil.Bytes)(msg.Data),
GasTipCap: (*hexutil.Big)(msg.GasTipCap),
GasFeeCap: (*hexutil.Big)(msg.GasFeeCap),
AccessList: msg.AccessList,
})
}
Loading

0 comments on commit 4f9aa1d

Please sign in to comment.