diff --git a/cli/wallet/legacy.go b/cli/wallet/legacy.go index 163353513..3ddbd6e5f 100644 --- a/cli/wallet/legacy.go +++ b/cli/wallet/legacy.go @@ -58,10 +58,7 @@ func (a *accountV2) convert(pass string) (*wallet.Account, error) { } address.Prefix = address.NEO3Prefix - newAcc, err := wallet.NewAccountFromWIF(priv.WIF()) - if err != nil { - return nil, err - } + newAcc := wallet.NewAccountFromPrivateKey(priv) if a.Contract != nil { script, err := hex.DecodeString(a.Contract.Script) if err != nil { diff --git a/pkg/core/helper_test.go b/pkg/core/helper_test.go index 91dfcbeca..e63207516 100644 --- a/pkg/core/helper_test.go +++ b/pkg/core/helper_test.go @@ -195,8 +195,7 @@ func TestCreateBasicChain(t *testing.T) { priv0 := testchain.PrivateKeyByID(0) priv1 := testchain.PrivateKeyByID(1) priv0ScriptHash := priv0.GetScriptHash() - acc0, err := wallet.NewAccountFromWIF(priv0.WIF()) - require.NoError(t, err) + acc0 := wallet.NewAccountFromPrivateKey(priv0) // Prepare some transaction for future submission. txSendRaw := newNEP17Transfer(bc.contracts.NEO.Hash, priv0ScriptHash, priv1.GetScriptHash(), int64(util.Fixed8FromInt64(1000))) @@ -268,8 +267,7 @@ func initBasicChain(t *testing.T, bc *Blockchain) { b.Header().EncodeBinary(buf.BinWriter) t.Logf("header: %s", hex.EncodeToString(buf.Bytes())) - acc0, err := wallet.NewAccountFromWIF(priv0.WIF()) - require.NoError(t, err) + acc0 := wallet.NewAccountFromPrivateKey(priv0) // Push some contract into the chain. txDeploy, cHash := newDeployTx(t, priv0ScriptHash, prefix+"test_contract.go", "Rubl") diff --git a/pkg/rpc/server/client_test.go b/pkg/rpc/server/client_test.go index 31467f76e..086fc4a98 100644 --- a/pkg/rpc/server/client_test.go +++ b/pkg/rpc/server/client_test.go @@ -132,16 +132,14 @@ func TestAddNetworkFee(t *testing.T) { t.Run("Contract", func(t *testing.T) { tx := transaction.New(testchain.Network(), []byte{byte(opcode.PUSH1)}, 0) priv := testchain.PrivateKeyByID(0) - acc1, err := wallet.NewAccountFromWIF(priv.WIF()) - require.NoError(t, err) + acc1 := wallet.NewAccountFromPrivateKey(priv) acc1.Contract.Deployed = true acc1.Contract.Script, _ = hex.DecodeString(verifyContractAVM) h, _ := util.Uint160DecodeStringLE(verifyContractHash) tx.ValidUntilBlock = chain.BlockHeight() + 10 t.Run("Valid", func(t *testing.T) { - acc0, err := wallet.NewAccountFromWIF(priv.WIF()) - require.NoError(t, err) + acc0 := wallet.NewAccountFromPrivateKey(priv) tx.Signers = []transaction.Signer{ { Account: acc0.PrivateKey().GetScriptHash(), @@ -173,8 +171,7 @@ func TestAddNetworkFee(t *testing.T) { require.Error(t, c.AddNetworkFee(tx, 10, acc0, acc1)) }) t.Run("InvalidContract", func(t *testing.T) { - acc0, err := wallet.NewAccountFromWIF(priv.WIF()) - require.NoError(t, err) + acc0 := wallet.NewAccountFromPrivateKey(priv) tx.Signers = []transaction.Signer{ { Account: acc0.PrivateKey().GetScriptHash(), @@ -200,8 +197,7 @@ func TestSignAndPushInvocationTx(t *testing.T) { require.NoError(t, c.Init()) priv := testchain.PrivateKey(0) - acc, err := wallet.NewAccountFromWIF(priv.WIF()) - require.NoError(t, err) + acc := wallet.NewAccountFromPrivateKey(priv) h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc, 30, 0, []transaction.Signer{{ Account: priv.GetScriptHash(), Scopes: transaction.CalledByEntry, @@ -239,8 +235,7 @@ func TestCreateTxFromScript(t *testing.T) { require.NoError(t, c.Init()) priv := testchain.PrivateKey(0) - acc, err := wallet.NewAccountFromWIF(priv.WIF()) - require.NoError(t, err) + acc := wallet.NewAccountFromPrivateKey(priv) t.Run("NoSystemFee", func(t *testing.T) { tx, err := c.CreateTxFromScript([]byte{byte(opcode.PUSH1)}, acc, -1, 10) require.NoError(t, err) @@ -269,8 +264,7 @@ func TestCreateNEP17TransferTx(t *testing.T) { require.NoError(t, c.Init()) priv := testchain.PrivateKeyByID(0) - acc, err := wallet.NewAccountFromWIF(priv.WIF()) - require.NoError(t, err) + acc := wallet.NewAccountFromPrivateKey(priv) gasContractHash, err := c.GetNativeContractHash("gas") require.NoError(t, err) diff --git a/pkg/rpc/server/server_test.go b/pkg/rpc/server/server_test.go index 42bd9a93c..8f9e2cc08 100644 --- a/pkg/rpc/server/server_test.go +++ b/pkg/rpc/server/server_test.go @@ -996,8 +996,7 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) [] }) priv0 := testchain.PrivateKeyByID(0) - acc0, err := wallet.NewAccountFromWIF(priv0.WIF()) - require.NoError(t, err) + acc0 := wallet.NewAccountFromPrivateKey(priv0) addNetworkFee := func(tx *transaction.Transaction) { size := io.GetVarSize(tx) diff --git a/pkg/wallet/account.go b/pkg/wallet/account.go index 7b871759b..0ecacfeb8 100644 --- a/pkg/wallet/account.go +++ b/pkg/wallet/account.go @@ -90,7 +90,7 @@ func NewAccount() (*Account, error) { if err != nil { return nil, err } - return newAccountFromPrivateKey(priv), nil + return NewAccountFromPrivateKey(priv), nil } // SignTx signs transaction t and updates it's Witnesses. @@ -172,7 +172,7 @@ func NewAccountFromWIF(wif string) (*Account, error) { if err != nil { return nil, err } - return newAccountFromPrivateKey(privKey), nil + return NewAccountFromPrivateKey(privKey), nil } // NewAccountFromEncryptedWIF creates a new Account from the given encrypted WIF. @@ -182,7 +182,7 @@ func NewAccountFromEncryptedWIF(wif string, pass string) (*Account, error) { return nil, err } - a := newAccountFromPrivateKey(priv) + a := NewAccountFromPrivateKey(priv) a.EncryptedWIF = wif return a, nil @@ -216,8 +216,8 @@ func (a *Account) ConvertMultisig(m int, pubs []*keys.PublicKey) error { return nil } -// newAccountFromPrivateKey creates a wallet from the given PrivateKey. -func newAccountFromPrivateKey(p *keys.PrivateKey) *Account { +// NewAccountFromPrivateKey creates a wallet from the given PrivateKey. +func NewAccountFromPrivateKey(p *keys.PrivateKey) *Account { pubKey := p.PublicKey() pubAddr := p.Address() wif := p.WIF()