wallet: export NewAccountFromPrivateKey()
Don't perform back-and-forth conversion, don't handle error which never occur.
This commit is contained in:
parent
239a8c3de7
commit
cd5219086a
5 changed files with 15 additions and 27 deletions
|
@ -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 {
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue