Skip to content
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

expose pub key to address #75

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions contract/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ type Txn struct {
value *big.Int
nonce uint64
gasLimit uint64
gasPrice uint64
GasPrice uint64
Data []byte
hash web3.Hash
}
Expand All @@ -182,7 +182,7 @@ func (t *Txn) EstimateGas() (uint64, error) {
To: t.to,
Data: t.Data,
Value: t.value,
GasPrice: t.gasPrice,
GasPrice: t.GasPrice,
}
return t.provider.Eth().EstimateGas(msg)
}
Expand Down Expand Up @@ -227,8 +227,8 @@ func (self *SignedTx) SendTransaction(signer *Signer) *web3.Receipt {
func (t *Txn) ToTransaction() (*web3.Transaction, error) {
var err error
// estimate gas price
if t.gasPrice == 0 {
t.gasPrice, err = t.provider.Eth().GasPrice()
if t.GasPrice == 0 {
t.GasPrice, err = t.provider.Eth().GasPrice()
if err != nil {
return nil, err
}
Expand All @@ -254,7 +254,7 @@ func (t *Txn) ToTransaction() (*web3.Transaction, error) {
txn := &web3.Transaction{
From: t.from,
Input: t.Data,
GasPrice: t.gasPrice,
GasPrice: t.GasPrice,
Gas: t.gasLimit,
Value: t.value,
Nonce: t.nonce,
Expand Down Expand Up @@ -282,7 +282,7 @@ func (t *Txn) Do() error {

// SetGasPrice sets the gas price of the transaction
func (t *Txn) SetGasPrice(gasPrice uint64) *Txn {
t.gasPrice = gasPrice
t.GasPrice = gasPrice
return t
}

Expand Down
9 changes: 4 additions & 5 deletions contract/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"strings"
"time"

"github.com/laizy/web3/executor/remotedb"

"github.com/laizy/web3"
"github.com/laizy/web3/executor"
"github.com/laizy/web3/executor/remotedb"
"github.com/laizy/web3/jsonrpc"
"github.com/laizy/web3/utils"
"github.com/laizy/web3/wallet"
Expand Down Expand Up @@ -97,16 +96,16 @@ func (self *Signer) WaitTx(hs web3.Hash) *web3.Receipt {
}
}

func (self *Signer) TransferEther(to web3.Address, value *big.Int, msg string) *web3.Transaction {
func (self *Signer) TransferEther(to web3.Address, value *big.Int, msg string) *Txn {
txn := &Txn{
from: self.Address(),
to: &to,
provider: self.Client,
Data: []byte(msg),
value: value,
}
tx := txn.MustToTransaction()
return self.SignTx(tx)

return txn
}

func (e *Signer) GetNonce(blockNumber web3.BlockNumber) (uint64, error) {
Expand Down
6 changes: 3 additions & 3 deletions wallet/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func newKey(priv *ecdsa.PrivateKey) *Key {
return &Key{
priv: priv,
pub: &priv.PublicKey,
addr: pubKeyToAddress(&priv.PublicKey),
addr: PubKeyToAddress(&priv.PublicKey),
}
}

func pubKeyToAddress(pub *ecdsa.PublicKey) (addr web3.Address) {
func PubKeyToAddress(pub *ecdsa.PublicKey) (addr web3.Address) {
b := keccak256(elliptic.Marshal(S256, pub.X, pub.Y)[1:])
copy(addr[:], b[12:])
return
Expand All @@ -89,7 +89,7 @@ func Ecrecover(hash, signature []byte) (web3.Address, error) {
if err != nil {
return web3.Address{}, err
}
return pubKeyToAddress(pub), nil
return PubKeyToAddress(pub), nil
}

func RecoverPubkey(signature, hash []byte) (*ecdsa.PublicKey, error) {
Expand Down
Loading