@@ -20,8 +20,8 @@ import (
2020
2121func DefaultWalletOptions () WalletOptions {
2222 return WalletOptions {
23- DerivationPath : "m/44'/60'/0'/0/0" ,
2423 RandomWalletEntropyBitSize : EntropyBitSize12WordMnemonic ,
24+ DerivationPath : "m/44'/60'/0'/0/0" ,
2525 }
2626}
2727
@@ -31,8 +31,8 @@ type Wallet struct {
3131}
3232
3333type WalletOptions struct {
34- DerivationPath string
3534 RandomWalletEntropyBitSize int
35+ DerivationPath string
3636}
3737
3838func NewWalletFromPrivateKey (hexPrivateKey string ) (* Wallet , error ) {
@@ -121,82 +121,36 @@ func (w *Wallet) SetProvider(provider *ethrpc.Provider) {
121121 w .provider = provider
122122}
123123
124- func (w * Wallet ) Transactor (ctx context.Context ) (* bind.TransactOpts , error ) {
125- var chainID * big.Int
126- if w .provider != nil {
127- var err error
128- chainID , err = w .provider .ChainID (ctx )
129- if err != nil {
130- return nil , err
131- }
132- }
133- return w .TransactorForChainID (chainID )
134- }
135-
136- func (w * Wallet ) TransactorForChainID (chainID * big.Int ) (* bind.TransactOpts , error ) {
137- if chainID == nil {
138- return nil , fmt .Errorf ("ethwallet: chainID is required" )
139- } else {
140- return bind .NewKeyedTransactorWithChainID (w .hdnode .PrivateKey (), chainID )
141- }
142- }
143-
144- // TODOXXX: deprecate?
145- func (w * Wallet ) SelfDerivePath (path accounts.DerivationPath ) (common.Address , error ) {
146- err := w .hdnode .DerivePath (path )
147- if err != nil {
148- return common.Address {}, err
149- }
150- return w .hdnode .Address (), nil
124+ func (w * Wallet ) Address () common.Address {
125+ return w .hdnode .Address ()
151126}
152127
153- func (w * Wallet ) DerivePath ( path accounts. DerivationPath ) (* Wallet , common.Address , error ) {
128+ func (w * Wallet ) DeriveFromPath ( derivationPath string ) (* Wallet , common.Address , error ) {
154129 wallet , err := w .Clone ()
155130 if err != nil {
156131 return nil , common.Address {}, err
157132 }
158- address , err := wallet .SelfDerivePath (path )
159- return wallet , address , err
160- }
161-
162- func (w * Wallet ) SelfDerivePathFromString (path string ) (common.Address , error ) {
163- err := w .hdnode .DerivePathFromString (path )
164- if err != nil {
165- return common.Address {}, err
166- }
167- return w .hdnode .Address (), nil
168- }
169-
170- func (w * Wallet ) DerivePathFromString (path string ) (* Wallet , common.Address , error ) {
171- wallet , err := w .Clone ()
133+ err = wallet .hdnode .DerivePathFromString (derivationPath )
172134 if err != nil {
173135 return nil , common.Address {}, err
174136 }
175- address , err := wallet .SelfDerivePathFromString ( path )
137+ address := wallet .hdnode . Address ( )
176138 return wallet , address , err
177139}
178140
179- func (w * Wallet ) SelfDeriveAccountIndex (accountIndex uint32 ) (common.Address , error ) {
180- err := w .hdnode . DeriveAccountIndex ( accountIndex )
141+ func (w * Wallet ) DeriveFromAccountIndex (accountIndex uint32 ) (* Wallet , common.Address , error ) {
142+ wallet , err := w .Clone ( )
181143 if err != nil {
182- return common.Address {}, err
144+ return nil , common.Address {}, err
183145 }
184- return w .hdnode .Address (), nil
185- }
186-
187- func (w * Wallet ) DeriveAccountIndex (accountIndex uint32 ) (* Wallet , common.Address , error ) {
188- wallet , err := w .Clone ()
146+ err = wallet .hdnode .DeriveAccountIndex (accountIndex )
189147 if err != nil {
190148 return nil , common.Address {}, err
191149 }
192- address , err := wallet .SelfDeriveAccountIndex ( accountIndex )
150+ address := wallet .hdnode . Address ( )
193151 return wallet , address , err
194152}
195153
196- func (w * Wallet ) Address () common.Address {
197- return w .hdnode .Address ()
198- }
199-
200154func (w * Wallet ) HDNode () * HDNode {
201155 return w .hdnode
202156}
@@ -219,6 +173,26 @@ func (w *Wallet) PublicKeyHex() string {
219173 return hexutil .Encode (publicKeyBytes )
220174}
221175
176+ func (w * Wallet ) Transactor (ctx context.Context ) (* bind.TransactOpts , error ) {
177+ var chainID * big.Int
178+ if w .provider != nil {
179+ var err error
180+ chainID , err = w .provider .ChainID (ctx )
181+ if err != nil {
182+ return nil , err
183+ }
184+ }
185+ return w .TransactorForChainID (chainID )
186+ }
187+
188+ func (w * Wallet ) TransactorForChainID (chainID * big.Int ) (* bind.TransactOpts , error ) {
189+ if chainID == nil {
190+ return nil , fmt .Errorf ("ethwallet: chainID is required" )
191+ } else {
192+ return bind .NewKeyedTransactorWithChainID (w .hdnode .PrivateKey (), chainID )
193+ }
194+ }
195+
222196func (w * Wallet ) GetBalance (ctx context.Context , optBlockNum ... * big.Int ) (* big.Int , error ) {
223197 var blockNum * big.Int = nil
224198 if len (optBlockNum ) > 0 {
0 commit comments