Skip to content

mobile: remove duplicated code #20888

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

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 2 additions & 18 deletions mobile/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package geth

import (
"errors"
"math/big"
"strings"

Expand All @@ -28,7 +27,6 @@ import (
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
)

// Signer is an interface defining the callback when a contract requires a
Expand Down Expand Up @@ -82,28 +80,14 @@ func NewTransactOpts() *TransactOpts {
return new(TransactOpts)
}

// NewKeyedTransactor is a utility method to easily create a transaction signer
// NewKeyedTransactOpts is a utility method to easily create a transaction signer
// from a single private key.
func NewKeyedTransactOpts(keyJson []byte, passphrase string) (*TransactOpts, error) {
key, err := keystore.DecryptKey(keyJson, passphrase)
if err != nil {
return nil, err
}
keyAddr := crypto.PubkeyToAddress(key.PrivateKey.PublicKey)
opts := bind.TransactOpts{
From: keyAddr,
Signer: func(signer types.Signer, address common.Address, tx *types.Transaction) (*types.Transaction, error) {
if address != keyAddr {
return nil, errors.New("not authorized to sign this account")
}
signature, err := crypto.Sign(signer.Hash(tx).Bytes(), key.PrivateKey)
if err != nil {
return nil, err
}
return tx.WithSignature(signer, signature)
},
}
return &TransactOpts{opts}, nil
return &TransactOpts{*bind.NewKeyedTransactor(key.PrivateKey)}, nil
}

func (opts *TransactOpts) GetFrom() *Address { return &Address{opts.opts.From} }
Expand Down