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

small wallet improvements #812

Merged
merged 2 commits into from
Mar 15, 2019
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
6 changes: 3 additions & 3 deletions commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type WalletExecutor interface {
List() ([]string, error)
Create(passphrase string) (string, error)
Delete(address string, passphrase string) (string, error)
Export(address string, passphrase string) (provider.EncryptedKeyJSONV3, error)
Import(account provider.EncryptedKeyJSONV3, passphrase string) (string, error)
Export(address string, passphrase string) (provider.WalletEncryptedKeyJSONV3, error)
Import(account provider.WalletEncryptedKeyJSONV3, passphrase string) (string, error)
ImportFromPrivateKey(privateKey string, passphrase string) (string, error)
Sign(address string, passphrase string, transaction *provider.Transaction) (string, error)
Sign(address string, passphrase string, transaction provider.Transaction) (string, error)
}

// Executor is an interface that keeps all commands interfaces.
Expand Down
11 changes: 5 additions & 6 deletions commands/provider/wallet_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package provider

import (
"encoding/json"
"errors"

"github.com/mesg-foundation/core/protobuf/coreapi"
)
Expand Down Expand Up @@ -43,17 +42,17 @@ func (p *WalletProvider) Delete(address string, passphrase string) (string, erro
}

// Export exports an account
func (p *WalletProvider) Export(address string, passphrase string) (EncryptedKeyJSONV3, error) {
func (p *WalletProvider) Export(address string, passphrase string) (WalletEncryptedKeyJSONV3, error) {
input := walletExportInputs{
Address: address,
Passphrase: passphrase,
}
var output EncryptedKeyJSONV3
var output WalletEncryptedKeyJSONV3
return output, p.call("export", &input, &output)
}

// Import imports an account into the wallet
func (p *WalletProvider) Import(account EncryptedKeyJSONV3, passphrase string) (string, error) {
func (p *WalletProvider) Import(account WalletEncryptedKeyJSONV3, passphrase string) (string, error) {
input := walletImportInputs{
Account: account,
Passphrase: passphrase,
Expand All @@ -74,7 +73,7 @@ func (p *WalletProvider) ImportFromPrivateKey(privateKey string, passphrase stri
}

// Sign signs a transaction
func (p *WalletProvider) Sign(address string, passphrase string, transaction *Transaction) (string, error) {
func (p *WalletProvider) Sign(address string, passphrase string, transaction Transaction) (string, error) {
input := walletSignInputs{
Address: address,
Passphrase: passphrase,
Expand Down Expand Up @@ -102,7 +101,7 @@ func (p *WalletProvider) parseResult(r *coreapi.ResultData, output interface{})
if err := json.Unmarshal([]byte(r.OutputData), &outputError); err != nil {
return err
}
return errors.New(outputError.Message)
return outputError
}
return json.Unmarshal([]byte(r.OutputData), &output)
}
27 changes: 20 additions & 7 deletions commands/provider/wallet_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type walletExportInputs struct {
}

type walletImportInputs struct {
Account EncryptedKeyJSONV3 `json:"account"`
Passphrase string `json:"passphrase"`
Account WalletEncryptedKeyJSONV3 `json:"account"`
Passphrase string `json:"passphrase"`
}

type walletImportFromPrivateKeyInputs struct {
Expand All @@ -52,17 +52,17 @@ type walletImportOutputSuccess struct {
}

type walletSignInputs struct {
Address string `json:"address"`
Passphrase string `json:"passphrase"`
Transaction *Transaction `json:"transaction"`
Address string `json:"address"`
Passphrase string `json:"passphrase"`
Transaction Transaction `json:"transaction"`
}

type walletSignOutputSuccess struct {
SignedTransaction string `json:"signedTransaction"`
}

// EncryptedKeyJSONV3 represents an Ethereum JSON v3 encrypted wallet
type EncryptedKeyJSONV3 struct {
// WalletEncryptedKeyJSONV3 represents an Ethereum JSON v3 encrypted wallet
type WalletEncryptedKeyJSONV3 struct {
Address string `json:"address"`
Crypto interface{} `json:"crypto"`
ID string `json:"id"`
Expand All @@ -79,3 +79,16 @@ type Transaction struct {
GasPrice string `json:"gasPrice"`
Data string `json:"data"`
}

// TransactionReceipt is the success output of task send signed transaction.
type TransactionReceipt struct {
Receipt struct {
BlockNumber uint `json:"blockNumber"`
From string `json:"from"`
GasUsed uint `json:"gasUsed"`
Status bool `json:"status"`
To string `json:"to"`
TransactionHash string `json:"transactionHash"`
TransactionIndex uint `json:"transactionIndex"`
} `json:"receipt"`
}
2 changes: 1 addition & 1 deletion commands/wallet_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type walletImportCmd struct {

privateKey string
jsonFile string
account provider.EncryptedKeyJSONV3
account provider.WalletEncryptedKeyJSONV3

e WalletExecutor
}
Expand Down