Update neo_client.go

This commit is contained in:
P4vlushaaa 2025-01-23 13:20:12 +03:00 committed by GitHub
parent 474679f042
commit 36938f47db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,47 +1,44 @@
package neo
import (
"context"
"fmt"
"context"
"fmt"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
"github.com/nspcc-dev/neo-go/pkg/wallet"
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
"github.com/nspcc-dev/neo-go/pkg/rpcclient/actor"
"github.com/nspcc-dev/neo-go/pkg/wallet"
)
type NeoClient struct {
Actor *actor.Actor
RPC *rpcclient.Client
Context context.Context
Actor *actor.Actor
RPC *rpcclient.Client
Context context.Context
}
func NewNeoClient(rpcEndpoint, walletPath, walletPass string) (*NeoClient, error) {
ctx := context.Background()
ctx := context.Background()
rpcCli, err := rpcclient.New(ctx, rpcEndpoint, rpcclient.Options{})
if err != nil {
return nil, fmt.Errorf("rpcclient new: %w", err)
}
rpcCli, err := rpcclient.New(ctx, rpcEndpoint, rpcclient.Options{})
if err != nil {
return nil, fmt.Errorf("rpcclient new: %w", err)
}
w, err := wallet.NewWalletFromFile(walletPath)
if err != nil {
return nil, fmt.Errorf("wallet load: %w", err)
}
acc := w.GetAccount(w.GetChangeAddress())
err = acc.Decrypt(walletPass, w.Scrypt)
if err != nil {
return nil, fmt.Errorf("wallet decrypt: %w", err)
}
act, err := actor.NewSimple(rpcCli, acc)
if err != nil {
return nil, fmt.Errorf("actor new: %w", err)
}
w, err := wallet.NewWalletFromFile(walletPath)
if err != nil {
return nil, fmt.Errorf("wallet load: %w", err)
}
acc := w.GetAccount(w.GetChangeAddress())
err = acc.Decrypt(walletPass, w.Scrypt)
if err != nil {
return nil, fmt.Errorf("wallet decrypt: %w", err)
}
act, err := actor.NewSimple(rpcCli, acc)
if err != nil {
return nil, fmt.Errorf("actor new: %w", err)
}
return &NeoClient{
Actor: act,
RPC: rpcCli,
Context: ctx,
}, nil
return &NeoClient{
Actor: act,
RPC: rpcCli,
Context: ctx,
}, nil
}