|
|
|
@ -32,14 +32,17 @@ import ( |
|
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// ExternalBackend is a struct for external backend
|
|
|
|
|
type ExternalBackend struct { |
|
|
|
|
signers []accounts.Wallet |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Wallets returns the list of wallets
|
|
|
|
|
func (eb *ExternalBackend) Wallets() []accounts.Wallet { |
|
|
|
|
return eb.signers |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewExternalBackend ...
|
|
|
|
|
func NewExternalBackend(endpoint string) (*ExternalBackend, error) { |
|
|
|
|
signer, err := NewExternalSigner(endpoint) |
|
|
|
|
if err != nil { |
|
|
|
@ -50,6 +53,7 @@ func NewExternalBackend(endpoint string) (*ExternalBackend, error) { |
|
|
|
|
}, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Subscribe ...
|
|
|
|
|
func (eb *ExternalBackend) Subscribe(sink chan<- accounts.WalletEvent) event.Subscription { |
|
|
|
|
return event.NewSubscription(func(quit <-chan struct{}) error { |
|
|
|
|
<-quit |
|
|
|
@ -68,6 +72,7 @@ type ExternalSigner struct { |
|
|
|
|
cache []accounts.Account |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewExternalSigner ...
|
|
|
|
|
func NewExternalSigner(endpoint string) (*ExternalSigner, error) { |
|
|
|
|
client, err := rpc.Dial(endpoint) |
|
|
|
|
if err != nil { |
|
|
|
@ -86,6 +91,7 @@ func NewExternalSigner(endpoint string) (*ExternalSigner, error) { |
|
|
|
|
return extsigner, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// URL ...
|
|
|
|
|
func (api *ExternalSigner) URL() accounts.URL { |
|
|
|
|
return accounts.URL{ |
|
|
|
|
Scheme: "extapi", |
|
|
|
@ -93,18 +99,22 @@ func (api *ExternalSigner) URL() accounts.URL { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Status ...
|
|
|
|
|
func (api *ExternalSigner) Status() (string, error) { |
|
|
|
|
return api.status, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Open ...
|
|
|
|
|
func (api *ExternalSigner) Open(passphrase string) error { |
|
|
|
|
return fmt.Errorf("operation not supported on external signers") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Close ...
|
|
|
|
|
func (api *ExternalSigner) Close() error { |
|
|
|
|
return fmt.Errorf("operation not supported on external signers") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Accounts ...
|
|
|
|
|
func (api *ExternalSigner) Accounts() []accounts.Account { |
|
|
|
|
var accnts []accounts.Account |
|
|
|
|
res, err := api.listAccounts() |
|
|
|
@ -127,6 +137,7 @@ func (api *ExternalSigner) Accounts() []accounts.Account { |
|
|
|
|
return accnts |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Contains ...
|
|
|
|
|
func (api *ExternalSigner) Contains(account accounts.Account) bool { |
|
|
|
|
api.cacheMu.RLock() |
|
|
|
|
defer api.cacheMu.RUnlock() |
|
|
|
@ -144,10 +155,12 @@ func (api *ExternalSigner) Contains(account accounts.Account) bool { |
|
|
|
|
return false |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Derive ...
|
|
|
|
|
func (api *ExternalSigner) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error) { |
|
|
|
|
return accounts.Account{}, fmt.Errorf("operation not supported on external signers") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SelfDerive ...
|
|
|
|
|
func (api *ExternalSigner) SelfDerive(bases []accounts.DerivationPath, chain ethereum.ChainStateReader) { |
|
|
|
|
log.Error("operation SelfDerive not supported on external signers") |
|
|
|
|
} |
|
|
|
@ -173,6 +186,7 @@ func (api *ExternalSigner) SignData(account accounts.Account, mimeType string, d |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SignText ...
|
|
|
|
|
func (api *ExternalSigner) SignText(account accounts.Account, text []byte) ([]byte, error) { |
|
|
|
|
var signature hexutil.Bytes |
|
|
|
|
var signAddress = common.NewMixedcaseAddress(account.Address) |
|
|
|
@ -196,6 +210,7 @@ type signTransactionResult struct { |
|
|
|
|
Tx *types.Transaction `json:"tx"` |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SignTx ...
|
|
|
|
|
func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) { |
|
|
|
|
data := hexutil.Bytes(tx.Data()) |
|
|
|
|
var to *common.MixedcaseAddress |
|
|
|
@ -219,13 +234,17 @@ func (api *ExternalSigner) SignTx(account accounts.Account, tx *types.Transactio |
|
|
|
|
return res.Tx, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SignTextWithPassphrase ...
|
|
|
|
|
func (api *ExternalSigner) SignTextWithPassphrase(account accounts.Account, passphrase string, text []byte) ([]byte, error) { |
|
|
|
|
return []byte{}, fmt.Errorf("password-operations not supported on external signers") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SignTxWithPassphrase ...
|
|
|
|
|
func (api *ExternalSigner) SignTxWithPassphrase(account accounts.Account, passphrase string, tx *types.Transaction, chainID *big.Int) (*types.Transaction, error) { |
|
|
|
|
return nil, fmt.Errorf("password-operations not supported on external signers") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// SignDataWithPassphrase ...
|
|
|
|
|
func (api *ExternalSigner) SignDataWithPassphrase(account accounts.Account, passphrase, mimeType string, data []byte) ([]byte, error) { |
|
|
|
|
return nil, fmt.Errorf("password-operations not supported on external signers") |
|
|
|
|
} |
|
|
|
|