Skip to content

Commit

Permalink
enable EIP-1559
Browse files Browse the repository at this point in the history
  • Loading branch information
rmanzoku committed Nov 30, 2021
1 parent c07f973 commit 684b38a
Show file tree
Hide file tree
Showing 5 changed files with 625 additions and 122 deletions.
19 changes: 17 additions & 2 deletions awseoa.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ func NewKMSTransactor(svc *kms.Client, id string, chainID *big.Int) (*bind.Trans
return nil, err
}

signer := types.LatestSignerForChainID(chainID)

return &bind.TransactOpts{
From: keyAddr,
Signer: func(address common.Address, tx *types.Transaction) (*types.Transaction, error) {
if address != keyAddr {
return nil, errors.New("not authorized to sign this account")
}
signer := types.NewEIP155Signer(s.chainID)
digest := signer.Hash(tx).Bytes()

sig, err := s.SignDigest(digest)
Expand Down Expand Up @@ -172,7 +173,10 @@ func (s Signer) SignDigest(digest []byte) (signature []byte, err error) {
sig.S = new(big.Int).Sub(secp256k1N, sig.S)
}

signature = append(sig.R.Bytes(), sig.S.Bytes()...)
sigr := pad32(sig.R.Bytes())
sigs := pad32(sig.S.Bytes())

signature = append(sigr, sigs...)

// Calc V
for _, v := range []int{0, 1} {
Expand Down Expand Up @@ -230,3 +234,14 @@ func toEthSignedMessageHash(message []byte) []byte {
func keccak256(data []byte) []byte {
return crypto.Keccak256(data)
}

func pad32(src []byte) []byte {
l := 32
if len(src) == l {
return src
}

dst := make([]byte, l)
copy(dst, src)
return dst
}
13 changes: 6 additions & 7 deletions cmd/sendEther/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var (
valueEther float64 = 0
from = ""
to = ""
gasGwei float64 = 1
)

func handler(ctx context.Context) (err error) {
Expand All @@ -29,7 +28,7 @@ func handler(ctx context.Context) (err error) {
return
}

fmt.Printf("Sending %f Ether from %s to %s gas: %f gwei\n", valueEther, from, to, gasGwei)
fmt.Printf("Sending %f Ether from %s to %s\n", valueEther, from, to)

ethcli, err := ethclient.Dial(rpc)
if err != nil {
Expand All @@ -53,11 +52,11 @@ func handler(ctx context.Context) (err error) {
if err != nil {
return err
}
topts.Context = context.TODO()
topts.GasPrice, err = awseoa.GweiToWei(gasGwei)
if err != nil {
return err
}
topts.Context = ctx
// topts.GasPrice, err = awseoa.GweiToWei(gasGwei)
// if err != nil {
// return err
// }

amount, err := awseoa.EtherToWei(valueEther)
if err != nil {
Expand Down
37 changes: 29 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,34 @@ module github.com/rmanzoku/go-awseoa/v2
go 1.15

require (
github.com/aws/aws-sdk-go-v2 v1.2.0
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VictoriaMetrics/fastcache v1.7.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.11.0
github.com/aws/aws-sdk-go-v2/config v1.1.1
github.com/aws/aws-sdk-go-v2/service/kms v1.1.1
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/ethereum/go-ethereum v1.9.25
github.com/shopspring/decimal v1.2.0
github.com/stretchr/testify v1.4.0
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
golang.org/x/sys v0.0.0-20210218085108-9555bcde0c6a // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.0 // indirect
github.com/aws/aws-sdk-go-v2/service/kms v1.9.0
github.com/deckarep/golang-set v1.7.1 // indirect
github.com/ethereum/go-ethereum v1.10.12
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 // indirect
github.com/go-kit/kit v0.9.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/shirou/gopsutil v3.21.10+incompatible // indirect
github.com/shopspring/decimal v1.3.1
github.com/status-im/keycard-go v0.0.0-20211109104530-b0e0482ba91d // indirect
github.com/stretchr/testify v1.7.0
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa // indirect
golang.org/x/net v0.0.0-20211109214657-ef0fda0de508 // indirect
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
Loading

0 comments on commit 684b38a

Please sign in to comment.