forked from TrueCloudLab/neoneo-go
commit
68b5260fb5
102 changed files with 794 additions and 908 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -50,7 +50,7 @@ testdata/
|
||||||
!pkg/compiler/testdata
|
!pkg/compiler/testdata
|
||||||
!pkg/config/testdata
|
!pkg/config/testdata
|
||||||
!pkg/consensus/testdata
|
!pkg/consensus/testdata
|
||||||
!pkg/rpc/server/testdata
|
!pkg/services/rpcsrv/testdata
|
||||||
!pkg/services/notary/testdata
|
!pkg/services/notary/testdata
|
||||||
!pkg/services/oracle/testdata
|
!pkg/services/oracle/testdata
|
||||||
!pkg/smartcontract/testdata
|
!pkg/smartcontract/testdata
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -188,14 +188,14 @@ func ParseParams(args []string, calledFromMain bool) (int, []smartcontract.Param
|
||||||
|
|
||||||
// GetSignersAccounts returns the list of signers combined with the corresponding
|
// GetSignersAccounts returns the list of signers combined with the corresponding
|
||||||
// accounts from the provided wallet.
|
// accounts from the provided wallet.
|
||||||
func GetSignersAccounts(wall *wallet.Wallet, signers []transaction.Signer) ([]client.SignerAccount, error) {
|
func GetSignersAccounts(wall *wallet.Wallet, signers []transaction.Signer) ([]rpcclient.SignerAccount, error) {
|
||||||
signersAccounts := make([]client.SignerAccount, len(signers))
|
signersAccounts := make([]rpcclient.SignerAccount, len(signers))
|
||||||
for i := range signers {
|
for i := range signers {
|
||||||
signerAcc := wall.GetAccount(signers[i].Account)
|
signerAcc := wall.GetAccount(signers[i].Account)
|
||||||
if signerAcc == nil {
|
if signerAcc == nil {
|
||||||
return nil, fmt.Errorf("no account was found in the wallet for signer #%d (%s)", i, address.Uint160ToString(signers[i].Account))
|
return nil, fmt.Errorf("no account was found in the wallet for signer #%d (%s)", i, address.Uint160ToString(signers[i].Account))
|
||||||
}
|
}
|
||||||
signersAccounts[i] = client.SignerAccount{
|
signersAccounts[i] = rpcclient.SignerAccount{
|
||||||
Signer: signers[i],
|
Signer: signers[i],
|
||||||
Account: signerAcc,
|
Account: signerAcc,
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
|
|
@ -20,7 +20,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network"
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server"
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
@ -56,7 +56,7 @@ type executor struct {
|
||||||
// Chain is a blockchain instance (can be empty).
|
// Chain is a blockchain instance (can be empty).
|
||||||
Chain *core.Blockchain
|
Chain *core.Blockchain
|
||||||
// RPC is an RPC server to query (can be empty).
|
// RPC is an RPC server to query (can be empty).
|
||||||
RPC *server.Server
|
RPC *rpcsrv.Server
|
||||||
// NetSrv is a network server (can be empty).
|
// NetSrv is a network server (can be empty).
|
||||||
NetSrv *network.Server
|
NetSrv *network.Server
|
||||||
// Out contains command output.
|
// Out contains command output.
|
||||||
|
@ -120,7 +120,7 @@ func (w *ConcurrentBuffer) Reset() {
|
||||||
w.buf.Reset()
|
w.buf.Reset()
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockchain, *server.Server, *network.Server) {
|
func newTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockchain, *rpcsrv.Server, *network.Server) {
|
||||||
configPath := "../config/protocol.unit_testnet.single.yml"
|
configPath := "../config/protocol.unit_testnet.single.yml"
|
||||||
cfg, err := config.LoadFile(configPath)
|
cfg, err := config.LoadFile(configPath)
|
||||||
require.NoError(t, err, "could not load config")
|
require.NoError(t, err, "could not load config")
|
||||||
|
@ -154,7 +154,7 @@ func newTestChain(t *testing.T, f func(*config.Config), run bool) (*core.Blockch
|
||||||
netSrv.AddExtensibleHPService(cons, consensus.Category, cons.OnPayload, cons.OnTransaction)
|
netSrv.AddExtensibleHPService(cons, consensus.Category, cons.OnPayload, cons.OnTransaction)
|
||||||
go netSrv.Start(make(chan error, 1))
|
go netSrv.Start(make(chan error, 1))
|
||||||
errCh := make(chan error, 2)
|
errCh := make(chan error, 2)
|
||||||
rpcServer := server.New(chain, cfg.ApplicationConfiguration.RPC, netSrv, nil, logger, errCh)
|
rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, netSrv, nil, logger, errCh)
|
||||||
rpcServer.Start()
|
rpcServer.Start()
|
||||||
|
|
||||||
return chain, &rpcServer, netSrv
|
return chain, &rpcServer, netSrv
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -70,12 +70,12 @@ func GetTimeoutContext(ctx *cli.Context) (context.Context, func()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRPCClient returns an RPC client instance for the given Context.
|
// GetRPCClient returns an RPC client instance for the given Context.
|
||||||
func GetRPCClient(gctx context.Context, ctx *cli.Context) (*client.Client, cli.ExitCoder) {
|
func GetRPCClient(gctx context.Context, ctx *cli.Context) (*rpcclient.Client, cli.ExitCoder) {
|
||||||
endpoint := ctx.String(RPCEndpointFlag)
|
endpoint := ctx.String(RPCEndpointFlag)
|
||||||
if len(endpoint) == 0 {
|
if len(endpoint) == 0 {
|
||||||
return nil, cli.NewExitError(errNoEndpoint, 1)
|
return nil, cli.NewExitError(errNoEndpoint, 1)
|
||||||
}
|
}
|
||||||
c, err := client.New(gctx, endpoint, client.Options{})
|
c, err := rpcclient.New(gctx, endpoint, rpcclient.Options{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, cli.NewExitError(err, 1)
|
return nil, cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm"
|
"github.com/nspcc-dev/neo-go/pkg/vm"
|
||||||
|
|
|
@ -21,10 +21,10 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network"
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/metrics"
|
"github.com/nspcc-dev/neo-go/pkg/services/metrics"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/notary"
|
"github.com/nspcc-dev/neo-go/pkg/services/notary"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/stateroot"
|
"github.com/nspcc-dev/neo-go/pkg/services/stateroot"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -505,7 +505,7 @@ func startServer(ctx *cli.Context) error {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
rpcServer := server.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
rpcServer := rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
||||||
serv.AddService(&rpcServer)
|
serv.AddService(&rpcServer)
|
||||||
|
|
||||||
go serv.Start(errChan)
|
go serv.Start(errChan)
|
||||||
|
@ -532,7 +532,7 @@ Main:
|
||||||
case syscall.SIGHUP:
|
case syscall.SIGHUP:
|
||||||
log.Info("SIGHUP received, restarting rpc-server")
|
log.Info("SIGHUP received, restarting rpc-server")
|
||||||
rpcServer.Shutdown()
|
rpcServer.Shutdown()
|
||||||
rpcServer = server.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
rpcServer = rpcsrv.New(chain, cfg.ApplicationConfiguration.RPC, serv, oracleSrv, log, errChan)
|
||||||
serv.AddService(&rpcServer) // Replaces old one by service name.
|
serv.AddService(&rpcServer) // Replaces old one by service name.
|
||||||
if !cfg.ApplicationConfiguration.RPC.StartWhenSynchronized || serv.IsInSync() {
|
if !cfg.ApplicationConfiguration.RPC.StartWhenSynchronized || serv.IsInSync() {
|
||||||
rpcServer.Start()
|
rpcServer.Start()
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc"
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -303,7 +302,7 @@ func TestConfigureAddresses(t *testing.T) {
|
||||||
t.Run("custom RPC address", func(t *testing.T) {
|
t.Run("custom RPC address", func(t *testing.T) {
|
||||||
cfg := &config.ApplicationConfiguration{
|
cfg := &config.ApplicationConfiguration{
|
||||||
Address: defaultAddress,
|
Address: defaultAddress,
|
||||||
RPC: rpc.Config{
|
RPC: config.RPC{
|
||||||
Address: customAddress,
|
Address: customAddress,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
||||||
|
@ -645,7 +645,7 @@ func invokeWithArgs(ctx *cli.Context, acc *wallet.Account, wall *wallet.Wallet,
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
gas, sysgas fixedn.Fixed8
|
gas, sysgas fixedn.Fixed8
|
||||||
cosignersAccounts []client.SignerAccount
|
cosignersAccounts []rpcclient.SignerAccount
|
||||||
resp *result.Invoke
|
resp *result.Invoke
|
||||||
sender util.Uint160
|
sender util.Uint160
|
||||||
signAndPush = acc != nil
|
signAndPush = acc != nil
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
|
@ -250,7 +250,7 @@ func transferNEP11(ctx *cli.Context) error {
|
||||||
return transferNEP(ctx, manifest.NEP11StandardName)
|
return transferNEP(ctx, manifest.NEP11StandardName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func signAndSendNEP11Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, token, to util.Uint160, tokenID []byte, amount *big.Int, data interface{}, cosigners []client.SignerAccount) error {
|
func signAndSendNEP11Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet.Account, token, to util.Uint160, tokenID []byte, amount *big.Int, data interface{}, cosigners []rpcclient.SignerAccount) error {
|
||||||
gas := flags.Fixed8FromContext(ctx, "gas")
|
gas := flags.Fixed8FromContext(ctx, "gas")
|
||||||
sysgas := flags.Fixed8FromContext(ctx, "sysgas")
|
sysgas := flags.Fixed8FromContext(ctx, "sysgas")
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
@ -278,7 +278,7 @@ func printAssetBalance(ctx *cli.Context, asset util.Uint160, tokenName, tokenSym
|
||||||
fmt.Fprintf(ctx.App.Writer, "\tUpdated: %d\n", balance.LastUpdated)
|
fmt.Fprintf(ctx.App.Writer, "\tUpdated: %d\n", balance.LastUpdated)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNativeNEP17Symbol(c *client.Client, name string) (string, util.Uint160, error) {
|
func getNativeNEP17Symbol(c *rpcclient.Client, name string) (string, util.Uint160, error) {
|
||||||
h, err := c.GetNativeContractHash(name)
|
h, err := c.GetNativeContractHash(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", util.Uint160{}, fmt.Errorf("failed to get native %s hash: %w", name, err)
|
return "", util.Uint160{}, fmt.Errorf("failed to get native %s hash: %w", name, err)
|
||||||
|
@ -296,7 +296,7 @@ func getMatchingToken(ctx *cli.Context, w *wallet.Wallet, name string, standard
|
||||||
}, len(w.Extra.Tokens), name, standard)
|
}, len(w.Extra.Tokens), name, standard)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMatchingTokenRPC(ctx *cli.Context, c *client.Client, addr util.Uint160, name string, standard string) (*wallet.Token, error) {
|
func getMatchingTokenRPC(ctx *cli.Context, c *rpcclient.Client, addr util.Uint160, name string, standard string) (*wallet.Token, error) {
|
||||||
switch standard {
|
switch standard {
|
||||||
case manifest.NEP17StandardName:
|
case manifest.NEP17StandardName:
|
||||||
bs, err := c.GetNEP17Balances(addr)
|
bs, err := c.GetNEP17Balances(addr)
|
||||||
|
@ -493,7 +493,7 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
||||||
return cli.NewExitError("empty recipients list", 1)
|
return cli.NewExitError("empty recipients list", 1)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
recipients []client.TransferTarget
|
recipients []rpcclient.TransferTarget
|
||||||
cosignersOffset = ctx.NArg()
|
cosignersOffset = ctx.NArg()
|
||||||
)
|
)
|
||||||
cache := make(map[string]*wallet.Token)
|
cache := make(map[string]*wallet.Token)
|
||||||
|
@ -526,7 +526,7 @@ func multiTransferNEP17(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1)
|
||||||
}
|
}
|
||||||
recipients = append(recipients, client.TransferTarget{
|
recipients = append(recipients, rpcclient.TransferTarget{
|
||||||
Token: token.Hash,
|
Token: token.Hash,
|
||||||
Address: addr,
|
Address: addr,
|
||||||
Amount: amount.Int64(),
|
Amount: amount.Int64(),
|
||||||
|
@ -608,7 +608,7 @@ func transferNEP(ctx *cli.Context, standard string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1)
|
return cli.NewExitError(fmt.Errorf("invalid amount: %w", err), 1)
|
||||||
}
|
}
|
||||||
return signAndSendNEP17Transfer(ctx, c, acc, []client.TransferTarget{{
|
return signAndSendNEP17Transfer(ctx, c, acc, []rpcclient.TransferTarget{{
|
||||||
Token: token.Hash,
|
Token: token.Hash,
|
||||||
Address: to,
|
Address: to,
|
||||||
Amount: amount.Int64(),
|
Amount: amount.Int64(),
|
||||||
|
@ -636,7 +636,7 @@ func transferNEP(ctx *cli.Context, standard string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func signAndSendNEP17Transfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget, cosigners []client.SignerAccount) error {
|
func signAndSendNEP17Transfer(ctx *cli.Context, c *rpcclient.Client, acc *wallet.Account, recipients []rpcclient.TransferTarget, cosigners []rpcclient.SignerAccount) error {
|
||||||
gas := flags.Fixed8FromContext(ctx, "gas")
|
gas := flags.Fixed8FromContext(ctx, "gas")
|
||||||
sysgas := flags.Fixed8FromContext(ctx, "sysgas")
|
sysgas := flags.Fixed8FromContext(ctx, "sysgas")
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
@ -125,7 +125,7 @@ func handleCandidate(ctx *cli.Context, method string, sysGas int64) error {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes())
|
emit.AppCall(w.BinWriter, neoContractHash, method, callflag.States, acc.PrivateKey().PublicKey().Bytes())
|
||||||
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
||||||
res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, sysGas, gas, []client.SignerAccount{{
|
res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, sysGas, gas, []rpcclient.SignerAccount{{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: acc.Contract.ScriptHash(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
|
@ -186,7 +186,7 @@ func handleVote(ctx *cli.Context) error {
|
||||||
emit.AppCall(w.BinWriter, neoContractHash, "vote", callflag.States, addr.BytesBE(), pubArg)
|
emit.AppCall(w.BinWriter, neoContractHash, "vote", callflag.States, addr.BytesBE(), pubArg)
|
||||||
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
emit.Opcodes(w.BinWriter, opcode.ASSERT)
|
||||||
|
|
||||||
res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, -1, gas, []client.SignerAccount{{
|
res, err := c.SignAndPushInvocationTx(w.Bytes(), acc, -1, gas, []rpcclient.SignerAccount{{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: acc.Contract.ScriptHash(),
|
Account: acc.Contract.ScriptHash(),
|
||||||
Scopes: transaction.CalledByEntry,
|
Scopes: transaction.CalledByEntry,
|
||||||
|
|
|
@ -255,7 +255,7 @@ won't pass verification.
|
||||||
Notary native contract supports `onNEP17Payment` method. Thus, to deposit funds to
|
Notary native contract supports `onNEP17Payment` method. Thus, to deposit funds to
|
||||||
the Notary native contract, transfer the desired amount of GAS to the contract
|
the Notary native contract, transfer the desired amount of GAS to the contract
|
||||||
address. Use
|
address. Use
|
||||||
[func (*Client) TransferNEP17](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.TransferNEP17)
|
[func (*Client) TransferNEP17](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.TransferNEP17)
|
||||||
with the `data` parameter matching the following requirements:
|
with the `data` parameter matching the following requirements:
|
||||||
- `data` should be an array of two elements: `to` and `till`.
|
- `data` should be an array of two elements: `to` and `till`.
|
||||||
- `to` denotes the receiver of the deposit. It can be nil in case `to` equals
|
- `to` denotes the receiver of the deposit. It can be nil in case `to` equals
|
||||||
|
@ -308,7 +308,7 @@ the steps to create a signature request:
|
||||||
constraints:
|
constraints:
|
||||||
* Notary signer hash is the hash of a native Notary contract that can be fetched
|
* Notary signer hash is the hash of a native Notary contract that can be fetched
|
||||||
from
|
from
|
||||||
[func (*Client) GetNativeContractHash](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.GetNativeContractHash).
|
[func (*Client) GetNativeContractHash](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.GetNativeContractHash).
|
||||||
* A notary signer must have `None` scope.
|
* A notary signer must have `None` scope.
|
||||||
* A notary signer shouldn't be placed at the beginning of the signer list
|
* A notary signer shouldn't be placed at the beginning of the signer list
|
||||||
because Notary contract does not pay main transaction fees. Other positions
|
because Notary contract does not pay main transaction fees. Other positions
|
||||||
|
@ -317,11 +317,11 @@ the steps to create a signature request:
|
||||||
field) and calculate system fee using regular rules (that will be `SystemFee`
|
field) and calculate system fee using regular rules (that will be `SystemFee`
|
||||||
transaction field). Probably, you'll perform one of these actions:
|
transaction field). Probably, you'll perform one of these actions:
|
||||||
1. If the script is a contract method call, use `invokefunction` RPC API
|
1. If the script is a contract method call, use `invokefunction` RPC API
|
||||||
[func (*Client) InvokeFunction](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.InvokeFunction)
|
[func (*Client) InvokeFunction](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.InvokeFunction)
|
||||||
and fetch the script and the gas consumed from the result.
|
and fetch the script and the gas consumed from the result.
|
||||||
2. If the script is more complicated than just a contract method call,
|
2. If the script is more complicated than just a contract method call,
|
||||||
construct the script manually and use `invokescript` RPC API
|
construct the script manually and use `invokescript` RPC API
|
||||||
[func (*Client) InvokeScript](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.InvokeScript)
|
[func (*Client) InvokeScript](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.InvokeScript)
|
||||||
to fetch the gas consumed from the result.
|
to fetch the gas consumed from the result.
|
||||||
3. Or just construct the script and set system fee manually.
|
3. Or just construct the script and set system fee manually.
|
||||||
3. Calculate the height main transaction is valid until (that will be
|
3. Calculate the height main transaction is valid until (that will be
|
||||||
|
@ -361,12 +361,12 @@ the steps to create a signature request:
|
||||||
`NotaryAssisted` attribute usage and for notary contract witness
|
`NotaryAssisted` attribute usage and for notary contract witness
|
||||||
verification (that is to be added by the notary node in the end of
|
verification (that is to be added by the notary node in the end of
|
||||||
signature collection process). Use
|
signature collection process). Use
|
||||||
[func (*Client) CalculateNotaryFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.CalculateNotaryFee)
|
[func (*Client) CalculateNotaryFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.CalculateNotaryFee)
|
||||||
to calculate notary network fee. Use `NKeys` estimated at step 4 as an
|
to calculate notary network fee. Use `NKeys` estimated at step 4 as an
|
||||||
argument.
|
argument.
|
||||||
- *Regular network fee.* That's the amount of GAS to be paid for other witnesses
|
- *Regular network fee.* That's the amount of GAS to be paid for other witnesses
|
||||||
verification. Use
|
verification. Use
|
||||||
[func (*Client) AddNetworkFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.AddNetworkFee)
|
[func (*Client) AddNetworkFee](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.AddNetworkFee)
|
||||||
to calculate regular network fee and add it to the transaction. Use
|
to calculate regular network fee and add it to the transaction. Use
|
||||||
partially-filled main transaction from the previous steps as `tx` argument.
|
partially-filled main transaction from the previous steps as `tx` argument.
|
||||||
Use notary network fee calculated at the previous substep as `extraFee`
|
Use notary network fee calculated at the previous substep as `extraFee`
|
||||||
|
@ -402,13 +402,13 @@ the steps to create a signature request:
|
||||||
tries to push all associated fallbacks. Use the following rules to define
|
tries to push all associated fallbacks. Use the following rules to define
|
||||||
`fallbackValidFor`:
|
`fallbackValidFor`:
|
||||||
- `fallbackValidFor` shouldn't be more than `MaxNotValidBeforeDelta` value.
|
- `fallbackValidFor` shouldn't be more than `MaxNotValidBeforeDelta` value.
|
||||||
- Use [func (*Client) GetMaxNotValidBeforeDelta](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.GetMaxNotValidBeforeDelta)
|
- Use [func (*Client) GetMaxNotValidBeforeDelta](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.GetMaxNotValidBeforeDelta)
|
||||||
to check `MaxNotValidBefore` value.
|
to check `MaxNotValidBefore` value.
|
||||||
11. Construct a script for the fallback transaction. The script may do something useful,
|
11. Construct a script for the fallback transaction. The script may do something useful,
|
||||||
i.g. invoke method of a contract. However, if you don't need to perform anything
|
i.g. invoke method of a contract. However, if you don't need to perform anything
|
||||||
special on fallback invocation, you can use simple `opcode.RET` script.
|
special on fallback invocation, you can use simple `opcode.RET` script.
|
||||||
12. Sign and submit P2P notary request. Use
|
12. Sign and submit P2P notary request. Use
|
||||||
[func (*Client) SignAndPushP2PNotaryRequest](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpc/client#Client.SignAndPushP2PNotaryRequest) for it.
|
[func (*Client) SignAndPushP2PNotaryRequest](https://pkg.go.dev/github.com/nspcc-dev/neo-go@v0.97.2/pkg/rpcclient#Client.SignAndPushP2PNotaryRequest) for it.
|
||||||
- Use the signed main transaction from step 8 as `mainTx` argument.
|
- Use the signed main transaction from step 8 as `mainTx` argument.
|
||||||
- Use the fallback script from step 10 as `fallbackScript` argument.
|
- Use the fallback script from step 10 as `fallbackScript` argument.
|
||||||
- Use `-1` as `fallbackSysFee` argument to define system fee by test
|
- Use `-1` as `fallbackSysFee` argument to define system fee by test
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client/nns"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
"github.com/nspcc-dev/neo-go/pkg/wallet"
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
"github.com/nspcc-dev/neo-go/pkg/core/mpt"
|
||||||
|
@ -19,7 +17,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
uatomic "go.uber.org/atomic"
|
uatomic "go.uber.org/atomic"
|
||||||
|
@ -93,16 +90,6 @@ func (chain *FakeChain) PutTx(tx *transaction.Transaction) {
|
||||||
chain.txs[tx.Hash()] = tx
|
chain.txs[tx.Hash()] = tx
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyPolicyToTxSet implements the Blockchainer interface.
|
|
||||||
func (chain *FakeChain) ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction {
|
|
||||||
panic("TODO")
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsTxStillRelevant implements the Blockchainer interface.
|
|
||||||
func (chain *FakeChain) IsTxStillRelevant(t *transaction.Transaction, txpool *mempool.Pool, isPartialTx bool) bool {
|
|
||||||
panic("TODO")
|
|
||||||
}
|
|
||||||
|
|
||||||
// InitVerificationContext initializes context for witness check.
|
// InitVerificationContext initializes context for witness check.
|
||||||
func (chain *FakeChain) InitVerificationContext(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error {
|
func (chain *FakeChain) InitVerificationContext(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
|
@ -210,11 +197,6 @@ func (chain *FakeChain) BlockHeight() uint32 {
|
||||||
return atomic.LoadUint32(&chain.Blockheight)
|
return atomic.LoadUint32(&chain.Blockheight)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close implements the Blockchainer interface.
|
|
||||||
func (chain *FakeChain) Close() {
|
|
||||||
panic("TODO")
|
|
||||||
}
|
|
||||||
|
|
||||||
// HeaderHeight implements the Blockchainer interface.
|
// HeaderHeight implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) HeaderHeight() uint32 {
|
func (chain *FakeChain) HeaderHeight() uint32 {
|
||||||
return atomic.LoadUint32(&chain.Blockheight)
|
return atomic.LoadUint32(&chain.Blockheight)
|
||||||
|
@ -310,11 +292,6 @@ func (chain *FakeChain) GetEnrollments() ([]state.Validator, error) {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStateModule implements the Blockchainer interface.
|
|
||||||
func (chain *FakeChain) GetStateModule() blockchainer.StateRoot {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetStorageItem implements the Blockchainer interface.
|
// GetStorageItem implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) GetStorageItem(id int32, key []byte) state.StorageItem {
|
func (chain *FakeChain) GetStorageItem(id int32, key []byte) state.StorageItem {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
|
@ -325,11 +302,6 @@ func (chain *FakeChain) GetTestVM(t trigger.Type, tx *transaction.Transaction, b
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentHeaderHash implements the Blockchainer interface.
|
|
||||||
func (chain *FakeChain) CurrentHeaderHash() util.Uint256 {
|
|
||||||
return util.Uint256{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// CurrentBlockHash implements the Blockchainer interface.
|
// CurrentBlockHash implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) CurrentBlockHash() util.Uint256 {
|
func (chain *FakeChain) CurrentBlockHash() util.Uint256 {
|
||||||
return util.Uint256{}
|
return util.Uint256{}
|
||||||
|
@ -373,26 +345,11 @@ func (chain *FakeChain) GetUtilityTokenBalance(uint160 util.Uint160) *big.Int {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ManagementContractHash implements the Blockchainer interface.
|
|
||||||
func (chain FakeChain) ManagementContractHash() util.Uint160 {
|
|
||||||
panic("TODO")
|
|
||||||
}
|
|
||||||
|
|
||||||
// PoolTx implements the Blockchainer interface.
|
// PoolTx implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) PoolTx(tx *transaction.Transaction, _ ...*mempool.Pool) error {
|
func (chain *FakeChain) PoolTx(tx *transaction.Transaction, _ ...*mempool.Pool) error {
|
||||||
return chain.PoolTxF(tx)
|
return chain.PoolTxF(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOracle implements the Blockchainer interface.
|
|
||||||
func (chain FakeChain) SetOracle(services.Oracle) {
|
|
||||||
panic("TODO")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetNotary implements the Blockchainer interface.
|
|
||||||
func (chain *FakeChain) SetNotary(notary services.Notary) {
|
|
||||||
panic("TODO")
|
|
||||||
}
|
|
||||||
|
|
||||||
// SubscribeForBlocks implements the Blockchainer interface.
|
// SubscribeForBlocks implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) SubscribeForBlocks(ch chan<- *block.Block) {
|
func (chain *FakeChain) SubscribeForBlocks(ch chan<- *block.Block) {
|
||||||
chain.blocksCh = append(chain.blocksCh, ch)
|
chain.blocksCh = append(chain.blocksCh, ch)
|
||||||
|
@ -404,7 +361,7 @@ func (chain *FakeChain) SubscribeForExecutions(ch chan<- *state.AppExecResult) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SubscribeForNotifications implements the Blockchainer interface.
|
// SubscribeForNotifications implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) SubscribeForNotifications(ch chan<- *subscriptions.NotificationEvent) {
|
func (chain *FakeChain) SubscribeForNotifications(ch chan<- *state.ContainedNotificationEvent) {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,7 +401,7 @@ func (chain *FakeChain) UnsubscribeFromExecutions(ch chan<- *state.AppExecResult
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnsubscribeFromNotifications implements the Blockchainer interface.
|
// UnsubscribeFromNotifications implements the Blockchainer interface.
|
||||||
func (chain *FakeChain) UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent) {
|
func (chain *FakeChain) UnsubscribeFromNotifications(ch chan<- *state.ContainedNotificationEvent) {
|
||||||
panic("TODO")
|
panic("TODO")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
@ -156,7 +155,7 @@ func SignCommittee(h hash.Hashable) []byte {
|
||||||
|
|
||||||
// NewBlock creates a new block for the given blockchain with the given offset
|
// NewBlock creates a new block for the given blockchain with the given offset
|
||||||
// (usually, 1), primary node index and transactions.
|
// (usually, 1), primary node index and transactions.
|
||||||
func NewBlock(t *testing.T, bc blockchainer.Blockchainer, offset uint32, primary uint32, txs ...*transaction.Transaction) *block.Block {
|
func NewBlock(t *testing.T, bc Ledger, offset uint32, primary uint32, txs ...*transaction.Transaction) *block.Block {
|
||||||
witness := transaction.Witness{VerificationScript: MultisigVerificationScript()}
|
witness := transaction.Witness{VerificationScript: MultisigVerificationScript()}
|
||||||
height := bc.BlockHeight()
|
height := bc.BlockHeight()
|
||||||
h := bc.GetHeaderHash(int(height))
|
h := bc.GetHeaderHash(int(height))
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/cli/smartcontract"
|
"github.com/nspcc-dev/neo-go/cli/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
"github.com/nspcc-dev/neo-go/pkg/compiler"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
|
@ -23,13 +23,24 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Ledger is an interface that abstracts the implementation of the blockchain.
|
||||||
|
type Ledger interface {
|
||||||
|
BlockHeight() uint32
|
||||||
|
FeePerByte() int64
|
||||||
|
GetBaseExecFee() int64
|
||||||
|
GetHeader(hash util.Uint256) (*block.Header, error)
|
||||||
|
GetHeaderHash(int) util.Uint256
|
||||||
|
HeaderHeight() uint32
|
||||||
|
ManagementContractHash() util.Uint160
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ownerHash = MultisigScriptHash()
|
ownerHash = MultisigScriptHash()
|
||||||
ownerScript = MultisigVerificationScript()
|
ownerScript = MultisigVerificationScript()
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTransferFromOwner returns a transaction transferring funds from NEO and GAS owner.
|
// NewTransferFromOwner returns a transaction transferring funds from NEO and GAS owner.
|
||||||
func NewTransferFromOwner(bc blockchainer.Blockchainer, contractHash, to util.Uint160, amount int64,
|
func NewTransferFromOwner(bc Ledger, contractHash, to util.Uint160, amount int64,
|
||||||
nonce, validUntil uint32) (*transaction.Transaction, error) {
|
nonce, validUntil uint32) (*transaction.Transaction, error) {
|
||||||
w := io.NewBufBinWriter()
|
w := io.NewBufBinWriter()
|
||||||
emit.AppCall(w.BinWriter, contractHash, "transfer", callflag.All, ownerHash, to, amount, nil)
|
emit.AppCall(w.BinWriter, contractHash, "transfer", callflag.All, ownerHash, to, amount, nil)
|
||||||
|
@ -53,7 +64,7 @@ func NewTransferFromOwner(bc blockchainer.Blockchainer, contractHash, to util.Ui
|
||||||
|
|
||||||
// NewDeployTx returns a new deployment transaction for a contract with the source from r and a name equal to
|
// NewDeployTx returns a new deployment transaction for a contract with the source from r and a name equal to
|
||||||
// the filename without '.go' suffix.
|
// the filename without '.go' suffix.
|
||||||
func NewDeployTx(bc blockchainer.Blockchainer, name string, sender util.Uint160, r gio.Reader, confFile *string) (*transaction.Transaction, util.Uint160, []byte, error) {
|
func NewDeployTx(bc Ledger, name string, sender util.Uint160, r gio.Reader, confFile *string) (*transaction.Transaction, util.Uint160, []byte, error) {
|
||||||
// nef.NewFile() cares about version a lot.
|
// nef.NewFile() cares about version a lot.
|
||||||
config.Version = "0.90.0-test"
|
config.Version = "0.90.0-test"
|
||||||
|
|
||||||
|
@ -111,18 +122,18 @@ func NewDeployTx(bc blockchainer.Blockchainer, name string, sender util.Uint160,
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignTx signs the provided transactions with validator keys.
|
// SignTx signs the provided transactions with validator keys.
|
||||||
func SignTx(bc blockchainer.Blockchainer, txs ...*transaction.Transaction) error {
|
func SignTx(bc Ledger, txs ...*transaction.Transaction) error {
|
||||||
signTxGeneric(bc, Sign, ownerScript, txs...)
|
signTxGeneric(bc, Sign, ownerScript, txs...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SignTxCommittee signs transactions by committee.
|
// SignTxCommittee signs transactions by committee.
|
||||||
func SignTxCommittee(bc blockchainer.Blockchainer, txs ...*transaction.Transaction) error {
|
func SignTxCommittee(bc Ledger, txs ...*transaction.Transaction) error {
|
||||||
signTxGeneric(bc, SignCommittee, CommitteeVerificationScript(), txs...)
|
signTxGeneric(bc, SignCommittee, CommitteeVerificationScript(), txs...)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func signTxGeneric(bc blockchainer.Blockchainer, sign func(hash.Hashable) []byte, verif []byte, txs ...*transaction.Transaction) {
|
func signTxGeneric(bc Ledger, sign func(hash.Hashable) []byte, verif []byte, txs ...*transaction.Transaction) {
|
||||||
for _, tx := range txs {
|
for _, tx := range txs {
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
netFee, sizeDelta := fee.Calculate(bc.GetBaseExecFee(), verif)
|
netFee, sizeDelta := fee.Calculate(bc.GetBaseExecFee(), verif)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
"github.com/nspcc-dev/neo-go/pkg/core/storage/dbconfig"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApplicationConfiguration config specific to the node.
|
// ApplicationConfiguration config specific to the node.
|
||||||
|
@ -22,7 +21,7 @@ type ApplicationConfiguration struct {
|
||||||
Prometheus BasicService `yaml:"Prometheus"`
|
Prometheus BasicService `yaml:"Prometheus"`
|
||||||
ProtoTickInterval int64 `yaml:"ProtoTickInterval"`
|
ProtoTickInterval int64 `yaml:"ProtoTickInterval"`
|
||||||
Relay bool `yaml:"Relay"`
|
Relay bool `yaml:"Relay"`
|
||||||
RPC rpc.Config `yaml:"RPC"`
|
RPC RPC `yaml:"RPC"`
|
||||||
UnlockWallet Wallet `yaml:"UnlockWallet"`
|
UnlockWallet Wallet `yaml:"UnlockWallet"`
|
||||||
Oracle OracleConfiguration `yaml:"Oracle"`
|
Oracle OracleConfiguration `yaml:"Oracle"`
|
||||||
P2PNotary P2PNotary `yaml:"P2PNotary"`
|
P2PNotary P2PNotary `yaml:"P2PNotary"`
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc"
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,7 +57,7 @@ func LoadFile(configPath string) (Config, error) {
|
||||||
ApplicationConfiguration: ApplicationConfiguration{
|
ApplicationConfiguration: ApplicationConfiguration{
|
||||||
PingInterval: 30,
|
PingInterval: 30,
|
||||||
PingTimeout: 90,
|
PingTimeout: 90,
|
||||||
RPC: rpc.Config{
|
RPC: RPC{
|
||||||
MaxIteratorResultItems: DefaultMaxIteratorResultItems,
|
MaxIteratorResultItems: DefaultMaxIteratorResultItems,
|
||||||
MaxFindResultItems: 100,
|
MaxFindResultItems: 100,
|
||||||
MaxNEP11Tokens: 100,
|
MaxNEP11Tokens: 100,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package rpc
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Config is an RPC service configuration information.
|
// RPC is an RPC service configuration information.
|
||||||
Config struct {
|
RPC struct {
|
||||||
Address string `yaml:"Address"`
|
Address string `yaml:"Address"`
|
||||||
Enabled bool `yaml:"Enabled"`
|
Enabled bool `yaml:"Enabled"`
|
||||||
EnableCORSWorkaround bool `yaml:"EnableCORSWorkaround"`
|
EnableCORSWorkaround bool `yaml:"EnableCORSWorkaround"`
|
||||||
|
@ -22,11 +22,11 @@ type (
|
||||||
SessionBackedByMPT bool `yaml:"SessionBackedByMPT"`
|
SessionBackedByMPT bool `yaml:"SessionBackedByMPT"`
|
||||||
SessionPoolSize int `yaml:"SessionPoolSize"`
|
SessionPoolSize int `yaml:"SessionPoolSize"`
|
||||||
StartWhenSynchronized bool `yaml:"StartWhenSynchronized"`
|
StartWhenSynchronized bool `yaml:"StartWhenSynchronized"`
|
||||||
TLSConfig TLSConfig `yaml:"TLSConfig"`
|
TLSConfig TLS `yaml:"TLSConfig"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TLSConfig describes SSL/TLS configuration.
|
// TLS describes SSL/TLS configuration.
|
||||||
TLSConfig struct {
|
TLS struct {
|
||||||
Address string `yaml:"Address"`
|
Address string `yaml:"Address"`
|
||||||
CertFile string `yaml:"CertFile"`
|
CertFile string `yaml:"CertFile"`
|
||||||
Enabled bool `yaml:"Enabled"`
|
Enabled bool `yaml:"Enabled"`
|
|
@ -13,9 +13,9 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
coreb "github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
|
@ -50,7 +50,7 @@ type Ledger interface {
|
||||||
GetConfig() config.ProtocolConfiguration
|
GetConfig() config.ProtocolConfiguration
|
||||||
GetMemPool() *mempool.Pool
|
GetMemPool() *mempool.Pool
|
||||||
GetNextBlockValidators() ([]*keys.PublicKey, error)
|
GetNextBlockValidators() ([]*keys.PublicKey, error)
|
||||||
GetStateModule() blockchainer.StateRoot
|
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||||
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
|
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
|
||||||
GetValidators() ([]*keys.PublicKey, error)
|
GetValidators() ([]*keys.PublicKey, error)
|
||||||
PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
|
PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
|
||||||
|
@ -250,7 +250,7 @@ func (s *service) newPrepareRequest() payload.PrepareRequest {
|
||||||
r := new(prepareRequest)
|
r := new(prepareRequest)
|
||||||
if s.ProtocolConfiguration.StateRootInHeader {
|
if s.ProtocolConfiguration.StateRootInHeader {
|
||||||
r.stateRootEnabled = true
|
r.stateRootEnabled = true
|
||||||
if sr, err := s.Chain.GetStateModule().GetStateRoot(s.dbft.BlockIndex - 1); err == nil {
|
if sr, err := s.Chain.GetStateRoot(s.dbft.BlockIndex - 1); err == nil {
|
||||||
r.stateRoot = sr.Root
|
r.stateRoot = sr.Root
|
||||||
} else {
|
} else {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -535,7 +535,7 @@ func (s *service) verifyRequest(p payload.ConsensusPayload) error {
|
||||||
return errInvalidVersion
|
return errInvalidVersion
|
||||||
}
|
}
|
||||||
if s.ProtocolConfiguration.StateRootInHeader {
|
if s.ProtocolConfiguration.StateRootInHeader {
|
||||||
sr, err := s.Chain.GetStateModule().GetStateRoot(s.dbft.BlockIndex - 1)
|
sr, err := s.Chain.GetStateRoot(s.dbft.BlockIndex - 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if sr.Root != req.stateRoot {
|
} else if sr.Root != req.stateRoot {
|
||||||
|
@ -689,7 +689,7 @@ func (s *service) newBlockFromContext(ctx *dbft.Context) block.Block {
|
||||||
block.Block.Nonce = ctx.Nonce
|
block.Block.Nonce = ctx.Nonce
|
||||||
block.Block.Index = ctx.BlockIndex
|
block.Block.Index = ctx.BlockIndex
|
||||||
if s.ProtocolConfiguration.StateRootInHeader {
|
if s.ProtocolConfiguration.StateRootInHeader {
|
||||||
sr, err := s.Chain.GetStateModule().GetStateRoot(ctx.BlockIndex - 1)
|
sr, err := s.Chain.GetStateRoot(ctx.BlockIndex - 1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Fatal(fmt.Sprintf("failed to get state root: %s", err.Error()))
|
s.log.Fatal(fmt.Sprintf("failed to get state root: %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,7 @@ func TestService_PrepareRequest(t *testing.T) {
|
||||||
prevHash: prevHash,
|
prevHash: prevHash,
|
||||||
})
|
})
|
||||||
|
|
||||||
sr, err := srv.Chain.GetStateModule().GetStateRoot(srv.dbft.BlockIndex - 1)
|
sr, err := srv.Chain.GetStateRoot(srv.dbft.BlockIndex - 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
checkRequest(t, errInvalidTransactionsCount, &prepareRequest{stateRootEnabled: true,
|
checkRequest(t, errInvalidTransactionsCount, &prepareRequest{stateRootEnabled: true,
|
||||||
|
|
|
@ -19,7 +19,7 @@ const (
|
||||||
// basicChainPrefix is a prefix used to store Basic chain .acc file for tests.
|
// basicChainPrefix is a prefix used to store Basic chain .acc file for tests.
|
||||||
// It is also used to retrieve smart contracts that should be deployed to
|
// It is also used to retrieve smart contracts that should be deployed to
|
||||||
// Basic chain.
|
// Basic chain.
|
||||||
basicChainPrefix = "../rpc/server/testdata/"
|
basicChainPrefix = "../services/rpcsrv/testdata/"
|
||||||
// bcPersistInterval is the time period Blockchain persists changes to the
|
// bcPersistInterval is the time period Blockchain persists changes to the
|
||||||
// underlying storage.
|
// underlying storage.
|
||||||
bcPersistInterval = time.Second
|
bcPersistInterval = time.Second
|
||||||
|
|
|
@ -15,8 +15,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/limits"
|
"github.com/nspcc-dev/neo-go/pkg/config/limits"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
||||||
|
@ -33,7 +31,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
|
@ -183,6 +180,18 @@ type Blockchain struct {
|
||||||
unsubCh chan interface{}
|
unsubCh chan interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StateRoot represents local state root module.
|
||||||
|
type StateRoot interface {
|
||||||
|
CurrentLocalHeight() uint32
|
||||||
|
CurrentLocalStateRoot() util.Uint256
|
||||||
|
CurrentValidatedHeight() uint32
|
||||||
|
FindStates(root util.Uint256, prefix, start []byte, max int) ([]storage.KeyValue, error)
|
||||||
|
GetState(root util.Uint256, key []byte) ([]byte, error)
|
||||||
|
GetStateProof(root util.Uint256, key []byte) ([][]byte, error)
|
||||||
|
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
||||||
|
GetLatestStateHeight(root util.Uint256) (uint32, error)
|
||||||
|
}
|
||||||
|
|
||||||
// bcEvent is an internal event generated by the Blockchain and then
|
// bcEvent is an internal event generated by the Blockchain and then
|
||||||
// broadcasted to other parties. It joins the new block and associated
|
// broadcasted to other parties. It joins the new block and associated
|
||||||
// invocation logs, all the other events visible from outside can be produced
|
// invocation logs, all the other events visible from outside can be produced
|
||||||
|
@ -292,7 +301,7 @@ func NewBlockchain(s storage.Store, cfg config.ProtocolConfiguration, log *zap.L
|
||||||
|
|
||||||
// SetOracle sets oracle module. It doesn't protected by mutex and
|
// SetOracle sets oracle module. It doesn't protected by mutex and
|
||||||
// must be called before `bc.Run()` to avoid data race.
|
// must be called before `bc.Run()` to avoid data race.
|
||||||
func (bc *Blockchain) SetOracle(mod services.Oracle) {
|
func (bc *Blockchain) SetOracle(mod native.OracleService) {
|
||||||
orc := bc.contracts.Oracle
|
orc := bc.contracts.Oracle
|
||||||
md, ok := orc.GetMethod(manifest.MethodVerify, -1)
|
md, ok := orc.GetMethod(manifest.MethodVerify, -1)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -306,7 +315,7 @@ func (bc *Blockchain) SetOracle(mod services.Oracle) {
|
||||||
|
|
||||||
// SetNotary sets notary module. It doesn't protected by mutex and
|
// SetNotary sets notary module. It doesn't protected by mutex and
|
||||||
// must be called before `bc.Run()` to avoid data race.
|
// must be called before `bc.Run()` to avoid data race.
|
||||||
func (bc *Blockchain) SetNotary(mod services.Notary) {
|
func (bc *Blockchain) SetNotary(mod native.NotaryService) {
|
||||||
bc.contracts.Designate.NotaryService.Store(mod)
|
bc.contracts.Designate.NotaryService.Store(mod)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -755,7 +764,7 @@ func (bc *Blockchain) notificationDispatcher() {
|
||||||
// expected, but maps are convenient for adding/deleting elements).
|
// expected, but maps are convenient for adding/deleting elements).
|
||||||
blockFeed = make(map[chan<- *block.Block]bool)
|
blockFeed = make(map[chan<- *block.Block]bool)
|
||||||
txFeed = make(map[chan<- *transaction.Transaction]bool)
|
txFeed = make(map[chan<- *transaction.Transaction]bool)
|
||||||
notificationFeed = make(map[chan<- *subscriptions.NotificationEvent]bool)
|
notificationFeed = make(map[chan<- *state.ContainedNotificationEvent]bool)
|
||||||
executionFeed = make(map[chan<- *state.AppExecResult]bool)
|
executionFeed = make(map[chan<- *state.AppExecResult]bool)
|
||||||
)
|
)
|
||||||
for {
|
for {
|
||||||
|
@ -768,7 +777,7 @@ func (bc *Blockchain) notificationDispatcher() {
|
||||||
blockFeed[ch] = true
|
blockFeed[ch] = true
|
||||||
case chan<- *transaction.Transaction:
|
case chan<- *transaction.Transaction:
|
||||||
txFeed[ch] = true
|
txFeed[ch] = true
|
||||||
case chan<- *subscriptions.NotificationEvent:
|
case chan<- *state.ContainedNotificationEvent:
|
||||||
notificationFeed[ch] = true
|
notificationFeed[ch] = true
|
||||||
case chan<- *state.AppExecResult:
|
case chan<- *state.AppExecResult:
|
||||||
executionFeed[ch] = true
|
executionFeed[ch] = true
|
||||||
|
@ -781,7 +790,7 @@ func (bc *Blockchain) notificationDispatcher() {
|
||||||
delete(blockFeed, ch)
|
delete(blockFeed, ch)
|
||||||
case chan<- *transaction.Transaction:
|
case chan<- *transaction.Transaction:
|
||||||
delete(txFeed, ch)
|
delete(txFeed, ch)
|
||||||
case chan<- *subscriptions.NotificationEvent:
|
case chan<- *state.ContainedNotificationEvent:
|
||||||
delete(notificationFeed, ch)
|
delete(notificationFeed, ch)
|
||||||
case chan<- *state.AppExecResult:
|
case chan<- *state.AppExecResult:
|
||||||
delete(executionFeed, ch)
|
delete(executionFeed, ch)
|
||||||
|
@ -801,7 +810,7 @@ func (bc *Blockchain) notificationDispatcher() {
|
||||||
}
|
}
|
||||||
for i := range aer.Events {
|
for i := range aer.Events {
|
||||||
for ch := range notificationFeed {
|
for ch := range notificationFeed {
|
||||||
ch <- &subscriptions.NotificationEvent{
|
ch <- &state.ContainedNotificationEvent{
|
||||||
Container: aer.Container,
|
Container: aer.Container,
|
||||||
NotificationEvent: aer.Events[i],
|
NotificationEvent: aer.Events[i],
|
||||||
}
|
}
|
||||||
|
@ -821,7 +830,7 @@ func (bc *Blockchain) notificationDispatcher() {
|
||||||
if aer.VMState == vmstate.Halt {
|
if aer.VMState == vmstate.Halt {
|
||||||
for i := range aer.Events {
|
for i := range aer.Events {
|
||||||
for ch := range notificationFeed {
|
for ch := range notificationFeed {
|
||||||
ch <- &subscriptions.NotificationEvent{
|
ch <- &state.ContainedNotificationEvent{
|
||||||
Container: aer.Container,
|
Container: aer.Container,
|
||||||
NotificationEvent: aer.Events[i],
|
NotificationEvent: aer.Events[i],
|
||||||
}
|
}
|
||||||
|
@ -842,7 +851,7 @@ func (bc *Blockchain) notificationDispatcher() {
|
||||||
}
|
}
|
||||||
for i := range aer.Events {
|
for i := range aer.Events {
|
||||||
for ch := range notificationFeed {
|
for ch := range notificationFeed {
|
||||||
ch <- &subscriptions.NotificationEvent{
|
ch <- &state.ContainedNotificationEvent{
|
||||||
Container: aer.Container,
|
Container: aer.Container,
|
||||||
NotificationEvent: aer.Events[i],
|
NotificationEvent: aer.Events[i],
|
||||||
}
|
}
|
||||||
|
@ -997,8 +1006,13 @@ func (bc *Blockchain) addHeaders(verify bool, headers ...*block.Header) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetStateRoot returns state root for the given height.
|
||||||
|
func (bc *Blockchain) GetStateRoot(height uint32) (*state.MPTRoot, error) {
|
||||||
|
return bc.stateRoot.GetStateRoot(height)
|
||||||
|
}
|
||||||
|
|
||||||
// GetStateModule returns state root service instance.
|
// GetStateModule returns state root service instance.
|
||||||
func (bc *Blockchain) GetStateModule() blockchainer.StateRoot {
|
func (bc *Blockchain) GetStateModule() StateRoot {
|
||||||
return bc.stateRoot
|
return bc.stateRoot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1782,7 +1796,7 @@ func (bc *Blockchain) SubscribeForTransactions(ch chan<- *transaction.Transactio
|
||||||
// transactions use SubscribeForExecutions instead. Make sure this channel is
|
// transactions use SubscribeForExecutions instead. Make sure this channel is
|
||||||
// read from regularly as not reading these events might affect other Blockchain
|
// read from regularly as not reading these events might affect other Blockchain
|
||||||
// functions.
|
// functions.
|
||||||
func (bc *Blockchain) SubscribeForNotifications(ch chan<- *subscriptions.NotificationEvent) {
|
func (bc *Blockchain) SubscribeForNotifications(ch chan<- *state.ContainedNotificationEvent) {
|
||||||
bc.subCh <- ch
|
bc.subCh <- ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1810,7 +1824,7 @@ func (bc *Blockchain) UnsubscribeFromTransactions(ch chan<- *transaction.Transac
|
||||||
// UnsubscribeFromNotifications unsubscribes given channel from new
|
// UnsubscribeFromNotifications unsubscribes given channel from new
|
||||||
// execution-generated notifications, you can close it afterwards. Passing
|
// execution-generated notifications, you can close it afterwards. Passing
|
||||||
// non-subscribed channel is a no-op.
|
// non-subscribed channel is a no-op.
|
||||||
func (bc *Blockchain) UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent) {
|
func (bc *Blockchain) UnsubscribeFromNotifications(ch chan<- *state.ContainedNotificationEvent) {
|
||||||
bc.unsubCh <- ch
|
bc.unsubCh <- ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
"github.com/nspcc-dev/neo-go/pkg/neotest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
"github.com/nspcc-dev/neo-go/pkg/neotest/chain"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -760,7 +759,7 @@ func TestBlockchain_Subscriptions(t *testing.T) {
|
||||||
const chBufSize = 16
|
const chBufSize = 16
|
||||||
blockCh := make(chan *block.Block, chBufSize)
|
blockCh := make(chan *block.Block, chBufSize)
|
||||||
txCh := make(chan *transaction.Transaction, chBufSize)
|
txCh := make(chan *transaction.Transaction, chBufSize)
|
||||||
notificationCh := make(chan *subscriptions.NotificationEvent, chBufSize)
|
notificationCh := make(chan *state.ContainedNotificationEvent, chBufSize)
|
||||||
executionCh := make(chan *state.AppExecResult, chBufSize)
|
executionCh := make(chan *state.AppExecResult, chBufSize)
|
||||||
|
|
||||||
bc, acc := chain.NewSingle(t)
|
bc, acc := chain.NewSingle(t)
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
package blockchainer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"math/big"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempool"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Blockchainer is an interface that abstracts the implementation
|
|
||||||
// of the blockchain.
|
|
||||||
type Blockchainer interface {
|
|
||||||
ApplyPolicyToTxSet([]*transaction.Transaction) []*transaction.Transaction
|
|
||||||
AddBlock(block *block.Block) error
|
|
||||||
AddHeaders(...*block.Header) error
|
|
||||||
BlockHeight() uint32
|
|
||||||
GetConfig() config.ProtocolConfiguration
|
|
||||||
CalculateClaimable(h util.Uint160, endHeight uint32) (*big.Int, error)
|
|
||||||
Close()
|
|
||||||
InitVerificationContext(ic *interop.Context, hash util.Uint160, witness *transaction.Witness) error
|
|
||||||
IsTxStillRelevant(t *transaction.Transaction, txpool *mempool.Pool, isPartialTx bool) bool
|
|
||||||
HeaderHeight() uint32
|
|
||||||
GetBlock(hash util.Uint256) (*block.Block, error)
|
|
||||||
GetCommittee() (keys.PublicKeys, error)
|
|
||||||
GetContractState(hash util.Uint160) *state.Contract
|
|
||||||
GetContractScriptHash(id int32) (util.Uint160, error)
|
|
||||||
GetEnrollments() ([]state.Validator, error)
|
|
||||||
GetGoverningTokenBalance(acc util.Uint160) (*big.Int, uint32)
|
|
||||||
ForEachNEP11Transfer(acc util.Uint160, newestTimestamp uint64, f func(*state.NEP11Transfer) (bool, error)) error
|
|
||||||
ForEachNEP17Transfer(acc util.Uint160, newestTimestamp uint64, f func(*state.NEP17Transfer) (bool, error)) error
|
|
||||||
GetHeaderHash(int) util.Uint256
|
|
||||||
GetHeader(hash util.Uint256) (*block.Header, error)
|
|
||||||
CurrentHeaderHash() util.Uint256
|
|
||||||
CurrentBlockHash() util.Uint256
|
|
||||||
HasBlock(util.Uint256) bool
|
|
||||||
HasTransaction(util.Uint256) bool
|
|
||||||
IsExtensibleAllowed(util.Uint160) bool
|
|
||||||
GetAppExecResults(util.Uint256, trigger.Type) ([]state.AppExecResult, error)
|
|
||||||
GetNotaryDepositExpiration(acc util.Uint160) uint32
|
|
||||||
GetNativeContractScriptHash(string) (util.Uint160, error)
|
|
||||||
GetNatives() []state.NativeContract
|
|
||||||
GetNextBlockValidators() ([]*keys.PublicKey, error)
|
|
||||||
GetNEP11Contracts() []util.Uint160
|
|
||||||
GetNEP17Contracts() []util.Uint160
|
|
||||||
GetTokenLastUpdated(acc util.Uint160) (map[int32]uint32, error)
|
|
||||||
GetNotaryContractScriptHash() util.Uint160
|
|
||||||
GetNotaryBalance(acc util.Uint160) *big.Int
|
|
||||||
GetNotaryServiceFeePerKey() int64
|
|
||||||
GetValidators() ([]*keys.PublicKey, error)
|
|
||||||
GetStateModule() StateRoot
|
|
||||||
GetStorageItem(id int32, key []byte) state.StorageItem
|
|
||||||
GetTestVM(t trigger.Type, tx *transaction.Transaction, b *block.Block) *interop.Context
|
|
||||||
GetTestHistoricVM(t trigger.Type, tx *transaction.Transaction, b *block.Block) (*interop.Context, error)
|
|
||||||
GetTransaction(util.Uint256) (*transaction.Transaction, uint32, error)
|
|
||||||
SetOracle(service services.Oracle)
|
|
||||||
mempool.Feer // fee interface
|
|
||||||
ManagementContractHash() util.Uint160
|
|
||||||
PoolTx(t *transaction.Transaction, pools ...*mempool.Pool) error
|
|
||||||
PoolTxWithData(t *transaction.Transaction, data interface{}, mp *mempool.Pool, feer mempool.Feer, verificationFunction func(t *transaction.Transaction, data interface{}) error) error
|
|
||||||
SetNotary(mod services.Notary)
|
|
||||||
SubscribeForBlocks(ch chan<- *block.Block)
|
|
||||||
SubscribeForExecutions(ch chan<- *state.AppExecResult)
|
|
||||||
SubscribeForNotifications(ch chan<- *subscriptions.NotificationEvent)
|
|
||||||
SubscribeForTransactions(ch chan<- *transaction.Transaction)
|
|
||||||
VerifyTx(*transaction.Transaction) error
|
|
||||||
VerifyWitness(util.Uint160, hash.Hashable, *transaction.Witness, int64) (int64, error)
|
|
||||||
GetMemPool() *mempool.Pool
|
|
||||||
UnsubscribeFromBlocks(ch chan<- *block.Block)
|
|
||||||
UnsubscribeFromExecutions(ch chan<- *state.AppExecResult)
|
|
||||||
UnsubscribeFromNotifications(ch chan<- *subscriptions.NotificationEvent)
|
|
||||||
UnsubscribeFromTransactions(ch chan<- *transaction.Transaction)
|
|
||||||
// Policer.
|
|
||||||
GetBaseExecFee() int64
|
|
||||||
GetMaxVerificationGAS() int64
|
|
||||||
GetStoragePrice() int64
|
|
||||||
FeePerByte() int64
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
package services
|
|
||||||
|
|
||||||
import "github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
|
|
||||||
// Notary is a Notary module interface.
|
|
||||||
type Notary interface {
|
|
||||||
UpdateNotaryNodes(pubs keys.PublicKeys)
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package services
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Oracle specifies oracle service interface.
|
|
||||||
type Oracle interface {
|
|
||||||
// AddRequests processes new requests.
|
|
||||||
AddRequests(map[uint64]*state.OracleRequest)
|
|
||||||
// RemoveRequests removes already processed requests.
|
|
||||||
RemoveRequests([]uint64)
|
|
||||||
// UpdateOracleNodes updates oracle nodes.
|
|
||||||
UpdateOracleNodes(keys.PublicKeys)
|
|
||||||
// UpdateNativeContract updates oracle contract native script and hash.
|
|
||||||
UpdateNativeContract([]byte, []byte, util.Uint160, int)
|
|
||||||
// Start runs oracle module.
|
|
||||||
Start()
|
|
||||||
// Shutdown shutdowns oracle module.
|
|
||||||
Shutdown()
|
|
||||||
}
|
|
|
@ -1,19 +0,0 @@
|
||||||
package blockchainer
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/storage"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// StateRoot represents local state root module.
|
|
||||||
type StateRoot interface {
|
|
||||||
CurrentLocalHeight() uint32
|
|
||||||
CurrentLocalStateRoot() util.Uint256
|
|
||||||
CurrentValidatedHeight() uint32
|
|
||||||
FindStates(root util.Uint256, prefix, start []byte, max int) ([]storage.KeyValue, error)
|
|
||||||
GetState(root util.Uint256, key []byte) ([]byte, error)
|
|
||||||
GetStateProof(root util.Uint256, key []byte) ([][]byte, error)
|
|
||||||
GetStateRoot(height uint32) (*state.MPTRoot, error)
|
|
||||||
GetLatestStateHeight(root util.Uint256) (uint32, error)
|
|
||||||
}
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/runtime"
|
||||||
|
@ -239,11 +238,11 @@ func (s *Designate) updateCachedRoleData(cache *DesignationCache, d *dao.Simple,
|
||||||
func (s *Designate) notifyRoleChanged(v *roleData, r noderoles.Role) {
|
func (s *Designate) notifyRoleChanged(v *roleData, r noderoles.Role) {
|
||||||
switch r {
|
switch r {
|
||||||
case noderoles.Oracle:
|
case noderoles.Oracle:
|
||||||
if orc, _ := s.OracleService.Load().(services.Oracle); orc != nil {
|
if orc, _ := s.OracleService.Load().(OracleService); orc != nil {
|
||||||
orc.UpdateOracleNodes(v.nodes.Copy())
|
orc.UpdateOracleNodes(v.nodes.Copy())
|
||||||
}
|
}
|
||||||
case noderoles.P2PNotary:
|
case noderoles.P2PNotary:
|
||||||
if ntr, _ := s.NotaryService.Load().(services.Notary); ntr != nil {
|
if ntr, _ := s.NotaryService.Load().(NotaryService); ntr != nil {
|
||||||
ntr.UpdateNotaryNodes(v.nodes.Copy())
|
ntr.UpdateNotaryNodes(v.nodes.Copy())
|
||||||
}
|
}
|
||||||
case noderoles.StateValidator:
|
case noderoles.StateValidator:
|
||||||
|
|
|
@ -38,6 +38,11 @@ type NotaryCache struct {
|
||||||
notaryServiceFeePerKey int64
|
notaryServiceFeePerKey int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NotaryService is a Notary module interface.
|
||||||
|
type NotaryService interface {
|
||||||
|
UpdateNotaryNodes(pubs keys.PublicKeys)
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
notaryContractID = -10
|
notaryContractID = -10
|
||||||
// prefixDeposit is a prefix for storing Notary deposits.
|
// prefixDeposit is a prefix for storing Notary deposits.
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer/services"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
"github.com/nspcc-dev/neo-go/pkg/core/dao"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
"github.com/nspcc-dev/neo-go/pkg/core/interop/contract"
|
||||||
|
@ -50,6 +49,22 @@ type OracleCache struct {
|
||||||
requestPrice int64
|
requestPrice int64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OracleService specifies oracle module interface.
|
||||||
|
type OracleService interface {
|
||||||
|
// AddRequests processes new requests.
|
||||||
|
AddRequests(map[uint64]*state.OracleRequest)
|
||||||
|
// RemoveRequests removes already processed requests.
|
||||||
|
RemoveRequests([]uint64)
|
||||||
|
// UpdateOracleNodes updates oracle nodes.
|
||||||
|
UpdateOracleNodes(keys.PublicKeys)
|
||||||
|
// UpdateNativeContract updates oracle contract native script and hash.
|
||||||
|
UpdateNativeContract([]byte, []byte, util.Uint160, int)
|
||||||
|
// Start runs oracle module.
|
||||||
|
Start()
|
||||||
|
// Shutdown shutdowns oracle module.
|
||||||
|
Shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
oracleContractID = -9
|
oracleContractID = -9
|
||||||
maxURLLength = 256
|
maxURLLength = 256
|
||||||
|
@ -164,7 +179,7 @@ func (o *Oracle) PostPersist(ic *interop.Context) error {
|
||||||
single := big.NewInt(p)
|
single := big.NewInt(p)
|
||||||
var removedIDs []uint64
|
var removedIDs []uint64
|
||||||
|
|
||||||
orc, _ := o.Module.Load().(services.Oracle)
|
orc, _ := o.Module.Load().(OracleService)
|
||||||
for _, tx := range ic.Block.Transactions {
|
for _, tx := range ic.Block.Transactions {
|
||||||
resp := getResponse(tx)
|
resp := getResponse(tx)
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
|
@ -521,7 +536,7 @@ func (o *Oracle) getConvertibleFromDAO(d *dao.Simple, key []byte, item stackitem
|
||||||
|
|
||||||
// updateCache updates cached Oracle values if they've been changed.
|
// updateCache updates cached Oracle values if they've been changed.
|
||||||
func (o *Oracle) updateCache(d *dao.Simple) error {
|
func (o *Oracle) updateCache(d *dao.Simple) error {
|
||||||
orc, _ := o.Module.Load().(services.Oracle)
|
orc, _ := o.Module.Load().(OracleService)
|
||||||
if orc == nil {
|
if orc == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,13 @@ type AppExecResult struct {
|
||||||
Execution
|
Execution
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContainedNotificationEvent represents a wrapper for a notification from script execution.
|
||||||
|
type ContainedNotificationEvent struct {
|
||||||
|
// Container hash is the hash of script container which is either a block or a transaction.
|
||||||
|
Container util.Uint256
|
||||||
|
NotificationEvent
|
||||||
|
}
|
||||||
|
|
||||||
// EncodeBinary implements the Serializable interface.
|
// EncodeBinary implements the Serializable interface.
|
||||||
func (ne *NotificationEvent) EncodeBinary(w *io.BinWriter) {
|
func (ne *NotificationEvent) EncodeBinary(w *io.BinWriter) {
|
||||||
ne.EncodeBinaryWithContext(w, stackitem.NewSerializationContext())
|
ne.EncodeBinaryWithContext(w, stackitem.NewSerializationContext())
|
||||||
|
@ -276,3 +283,42 @@ func (e *Execution) UnmarshalJSON(data []byte) error {
|
||||||
e.FaultException = aux.FaultException
|
e.FaultException = aux.FaultException
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// containedNotificationEventAux is an auxiliary struct for JSON marshalling.
|
||||||
|
type containedNotificationEventAux struct {
|
||||||
|
Container util.Uint256 `json:"container"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements the json.Marshaler interface.
|
||||||
|
func (ne *ContainedNotificationEvent) MarshalJSON() ([]byte, error) {
|
||||||
|
h, err := json.Marshal(&containedNotificationEventAux{
|
||||||
|
Container: ne.Container,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to marshal hash: %w", err)
|
||||||
|
}
|
||||||
|
exec, err := json.Marshal(ne.NotificationEvent)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to marshal execution: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if h[len(h)-1] != '}' || exec[0] != '{' {
|
||||||
|
return nil, errors.New("can't merge internal jsons")
|
||||||
|
}
|
||||||
|
h[len(h)-1] = ','
|
||||||
|
h = append(h, exec[1:]...)
|
||||||
|
return h, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements the json.Unmarshaler interface.
|
||||||
|
func (ne *ContainedNotificationEvent) UnmarshalJSON(data []byte) error {
|
||||||
|
aux := new(containedNotificationEventAux)
|
||||||
|
if err := json.Unmarshal(data, aux); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(data, &ne.NotificationEvent); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ne.Container = aux.Container
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
"github.com/nspcc-dev/neo-go/pkg/vm/vmstate"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
@ -241,3 +242,14 @@ func TestMarshalUnmarshalJSONAppExecResult(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContainedNotificationEvent_MarshalUnmarshalJSON(t *testing.T) {
|
||||||
|
testserdes.MarshalUnmarshalJSON(t, &ContainedNotificationEvent{
|
||||||
|
Container: util.Uint256{1, 2, 3},
|
||||||
|
NotificationEvent: NotificationEvent{
|
||||||
|
ScriptHash: util.Uint160{4, 5, 6},
|
||||||
|
Name: "alarm",
|
||||||
|
Item: stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte("qwerty"))}),
|
||||||
|
},
|
||||||
|
}, new(ContainedNotificationEvent))
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package response
|
package neorpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package response
|
package neorpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
||||||
package subscriptions
|
package result
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
"github.com/nspcc-dev/neo-go/pkg/core/mempoolevent"
|
|
@ -1,4 +1,9 @@
|
||||||
package request
|
/*
|
||||||
|
Package neorpc contains a set of types used for JSON-RPC communication with Neo servers.
|
||||||
|
It defines basic request/response types as well as a set of errors and additional
|
||||||
|
parameters used for specific requests/responses.
|
||||||
|
*/
|
||||||
|
package neorpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -17,10 +22,10 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Raw represents JSON-RPC request. It's generic enough to be used in many
|
// Request represents JSON-RPC request. It's generic enough to be used in many
|
||||||
// generic JSON-RPC communication scenarios, yet at the same time it's
|
// generic JSON-RPC communication scenarios, yet at the same time it's
|
||||||
// tailored for NeoGo RPC Client needs.
|
// tailored for NeoGo RPC Client needs.
|
||||||
Raw struct {
|
Request struct {
|
||||||
// JSONRPC is the protocol version, only valid when it contains JSONRPCVersion.
|
// JSONRPC is the protocol version, only valid when it contains JSONRPCVersion.
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
// Method is the method being called.
|
// Method is the method being called.
|
||||||
|
@ -37,6 +42,35 @@ type (
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Header is a generic JSON-RPC 2.0 response header (ID and JSON-RPC version).
|
||||||
|
Header struct {
|
||||||
|
ID json.RawMessage `json:"id"`
|
||||||
|
JSONRPC string `json:"jsonrpc"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// HeaderAndError adds an Error (that can be empty) to the Header, it's used
|
||||||
|
// to construct type-specific responses.
|
||||||
|
HeaderAndError struct {
|
||||||
|
Header
|
||||||
|
Error *Error `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw represents a standard raw JSON-RPC 2.0
|
||||||
|
// response: http://www.jsonrpc.org/specification#response_object.
|
||||||
|
Response struct {
|
||||||
|
HeaderAndError
|
||||||
|
Result json.RawMessage `json:"result,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notification is a type used to represent wire format of events, they're
|
||||||
|
// special in that they look like requests but they don't have IDs and their
|
||||||
|
// "method" is actually an event name.
|
||||||
|
Notification struct {
|
||||||
|
JSONRPC string `json:"jsonrpc"`
|
||||||
|
Event EventID `json:"method"`
|
||||||
|
Payload []interface{} `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
// BlockFilter is a wrapper structure for the block event filter. The only
|
// BlockFilter is a wrapper structure for the block event filter. The only
|
||||||
// allowed filter is primary index.
|
// allowed filter is primary index.
|
||||||
BlockFilter struct {
|
BlockFilter struct {
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/blockchainer"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
"github.com/nspcc-dev/neo-go/pkg/core/fee"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
"github.com/nspcc-dev/neo-go/pkg/core/native"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
|
@ -29,7 +29,7 @@ import (
|
||||||
|
|
||||||
// Executor is a wrapper over chain state.
|
// Executor is a wrapper over chain state.
|
||||||
type Executor struct {
|
type Executor struct {
|
||||||
Chain blockchainer.Blockchainer
|
Chain *core.Blockchain
|
||||||
Validator Signer
|
Validator Signer
|
||||||
Committee Signer
|
Committee Signer
|
||||||
CommitteeHash util.Uint160
|
CommitteeHash util.Uint160
|
||||||
|
@ -37,7 +37,7 @@ type Executor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExecutor creates a new executor instance from the provided blockchain and committee.
|
// NewExecutor creates a new executor instance from the provided blockchain and committee.
|
||||||
func NewExecutor(t testing.TB, bc blockchainer.Blockchainer, validator, committee Signer) *Executor {
|
func NewExecutor(t testing.TB, bc *core.Blockchain, validator, committee Signer) *Executor {
|
||||||
checkMultiSigner(t, validator)
|
checkMultiSigner(t, validator)
|
||||||
checkMultiSigner(t, committee)
|
checkMultiSigner(t, committee)
|
||||||
|
|
||||||
|
@ -254,12 +254,12 @@ func (e *Executor) EnsureGASBalance(t testing.TB, acc util.Uint160, isOk func(ba
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeployTx returns a new deployment tx for the contract signed by the committee.
|
// NewDeployTx returns a new deployment tx for the contract signed by the committee.
|
||||||
func (e *Executor) NewDeployTx(t testing.TB, bc blockchainer.Blockchainer, c *Contract, data interface{}) *transaction.Transaction {
|
func (e *Executor) NewDeployTx(t testing.TB, bc *core.Blockchain, c *Contract, data interface{}) *transaction.Transaction {
|
||||||
return NewDeployTxBy(t, bc, e.Validator, c, data)
|
return NewDeployTxBy(t, bc, e.Validator, c, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDeployTxBy returns a new deployment tx for the contract signed by the specified signer.
|
// NewDeployTxBy returns a new deployment tx for the contract signed by the specified signer.
|
||||||
func NewDeployTxBy(t testing.TB, bc blockchainer.Blockchainer, signer Signer, c *Contract, data interface{}) *transaction.Transaction {
|
func NewDeployTxBy(t testing.TB, bc *core.Blockchain, signer Signer, c *Contract, data interface{}) *transaction.Transaction {
|
||||||
rawManifest, err := json.Marshal(c.Manifest)
|
rawManifest, err := json.Marshal(c.Manifest)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ func NewDeployTxBy(t testing.TB, bc blockchainer.Blockchainer, signer Signer, c
|
||||||
|
|
||||||
// AddSystemFee adds system fee to the transaction. If negative value specified,
|
// AddSystemFee adds system fee to the transaction. If negative value specified,
|
||||||
// then system fee is defined by test invocation.
|
// then system fee is defined by test invocation.
|
||||||
func AddSystemFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, sysFee int64) {
|
func AddSystemFee(bc *core.Blockchain, tx *transaction.Transaction, sysFee int64) {
|
||||||
if sysFee >= 0 {
|
if sysFee >= 0 {
|
||||||
tx.SystemFee = sysFee
|
tx.SystemFee = sysFee
|
||||||
return
|
return
|
||||||
|
@ -294,7 +294,7 @@ func AddSystemFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, sys
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNetworkFee adds network fee to the transaction.
|
// AddNetworkFee adds network fee to the transaction.
|
||||||
func AddNetworkFee(bc blockchainer.Blockchainer, tx *transaction.Transaction, signers ...Signer) {
|
func AddNetworkFee(bc *core.Blockchain, tx *transaction.Transaction, signers ...Signer) {
|
||||||
baseFee := bc.GetBaseExecFee()
|
baseFee := bc.GetBaseExecFee()
|
||||||
size := io.GetVarSize(tx)
|
size := io.GetVarSize(tx)
|
||||||
for _, sgr := range signers {
|
for _, sgr := range signers {
|
||||||
|
@ -362,7 +362,7 @@ func (e *Executor) AddBlockCheckHalt(t testing.TB, txs ...*transaction.Transacti
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestInvoke creates a test VM with a dummy block and executes a transaction in it.
|
// TestInvoke creates a test VM with a dummy block and executes a transaction in it.
|
||||||
func TestInvoke(bc blockchainer.Blockchainer, tx *transaction.Transaction) (*vm.VM, error) {
|
func TestInvoke(bc *core.Blockchain, tx *transaction.Transaction) (*vm.VM, error) {
|
||||||
lastBlock, err := bc.GetBlock(bc.GetHeaderHash(int(bc.BlockHeight())))
|
lastBlock, err := bc.GetBlock(bc.GetHeaderHash(int(bc.BlockHeight())))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
package subscriptions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// NotificationEvent represents a wrapper for a notification from script execution.
|
|
||||||
type NotificationEvent struct {
|
|
||||||
// Container hash is the hash of script container which is either a block or a transaction.
|
|
||||||
Container util.Uint256
|
|
||||||
state.NotificationEvent
|
|
||||||
}
|
|
||||||
|
|
||||||
// notificationEventAux is an auxiliary struct for JSON marshalling.
|
|
||||||
type notificationEventAux struct {
|
|
||||||
Container util.Uint256 `json:"container"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface.
|
|
||||||
func (ne *NotificationEvent) MarshalJSON() ([]byte, error) {
|
|
||||||
h, err := json.Marshal(¬ificationEventAux{
|
|
||||||
Container: ne.Container,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to marshal hash: %w", err)
|
|
||||||
}
|
|
||||||
exec, err := json.Marshal(ne.NotificationEvent)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to marshal execution: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if h[len(h)-1] != '}' || exec[0] != '{' {
|
|
||||||
return nil, errors.New("can't merge internal jsons")
|
|
||||||
}
|
|
||||||
h[len(h)-1] = ','
|
|
||||||
h = append(h, exec[1:]...)
|
|
||||||
return h, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaler interface.
|
|
||||||
func (ne *NotificationEvent) UnmarshalJSON(data []byte) error {
|
|
||||||
aux := new(notificationEventAux)
|
|
||||||
if err := json.Unmarshal(data, aux); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := json.Unmarshal(data, &ne.NotificationEvent); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
ne.Container = aux.Container
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package subscriptions
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/internal/testserdes"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestNotificationEvent_MarshalUnmarshalJSON(t *testing.T) {
|
|
||||||
testserdes.MarshalUnmarshalJSON(t, &NotificationEvent{
|
|
||||||
Container: util.Uint256{1, 2, 3},
|
|
||||||
NotificationEvent: state.NotificationEvent{
|
|
||||||
ScriptHash: util.Uint160{4, 5, 6},
|
|
||||||
Name: "alarm",
|
|
||||||
Item: stackitem.NewArray([]stackitem.Item{stackitem.NewByteArray([]byte("qwerty"))}),
|
|
||||||
},
|
|
||||||
}, new(NotificationEvent))
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
package response
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Header is a generic JSON-RPC 2.0 response header (ID and JSON-RPC version).
|
|
||||||
type Header struct {
|
|
||||||
ID json.RawMessage `json:"id"`
|
|
||||||
JSONRPC string `json:"jsonrpc"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// HeaderAndError adds an Error (that can be empty) to the Header, it's used
|
|
||||||
// to construct type-specific responses.
|
|
||||||
type HeaderAndError struct {
|
|
||||||
Header
|
|
||||||
Error *Error `json:"error,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Raw represents a standard raw JSON-RPC 2.0
|
|
||||||
// response: http://www.jsonrpc.org/specification#response_object.
|
|
||||||
type Raw struct {
|
|
||||||
HeaderAndError
|
|
||||||
Result json.RawMessage `json:"result,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notification is a type used to represent wire format of events, they're
|
|
||||||
// special in that they look like requests but they don't have IDs and their
|
|
||||||
// "method" is actually an event name.
|
|
||||||
type Notification struct {
|
|
||||||
JSONRPC string `json:"jsonrpc"`
|
|
||||||
Event EventID `json:"method"`
|
|
||||||
Payload []interface{} `json:"params"`
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -13,8 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
)
|
)
|
||||||
|
@ -34,7 +33,7 @@ type Client struct {
|
||||||
endpoint *url.URL
|
endpoint *url.URL
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
opts Options
|
opts Options
|
||||||
requestF func(*request.Raw) (*response.Raw, error)
|
requestF func(*neorpc.Request) (*neorpc.Response, error)
|
||||||
|
|
||||||
cacheLock sync.RWMutex
|
cacheLock sync.RWMutex
|
||||||
// cache stores RPC node related information the client is bound to.
|
// cache stores RPC node related information the client is bound to.
|
||||||
|
@ -176,8 +175,8 @@ func (c *Client) performRequest(method string, p []interface{}, v interface{}) e
|
||||||
if p == nil {
|
if p == nil {
|
||||||
p = []interface{}{} // neo-project/neo-modules#742
|
p = []interface{}{} // neo-project/neo-modules#742
|
||||||
}
|
}
|
||||||
var r = request.Raw{
|
var r = neorpc.Request{
|
||||||
JSONRPC: request.JSONRPCVersion,
|
JSONRPC: neorpc.JSONRPCVersion,
|
||||||
Method: method,
|
Method: method,
|
||||||
Params: p,
|
Params: p,
|
||||||
ID: c.getNextRequestID(),
|
ID: c.getNextRequestID(),
|
||||||
|
@ -195,10 +194,10 @@ func (c *Client) performRequest(method string, p []interface{}, v interface{}) e
|
||||||
return json.Unmarshal(raw.Result, v)
|
return json.Unmarshal(raw.Result, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) makeHTTPRequest(r *request.Raw) (*response.Raw, error) {
|
func (c *Client) makeHTTPRequest(r *neorpc.Request) (*neorpc.Response, error) {
|
||||||
var (
|
var (
|
||||||
buf = new(bytes.Buffer)
|
buf = new(bytes.Buffer)
|
||||||
raw = new(response.Raw)
|
raw = new(neorpc.Response)
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := json.NewEncoder(buf).Encode(r); err != nil {
|
if err := json.NewEncoder(buf).Encode(r); err != nil {
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Package client implements NEO-specific JSON-RPC 2.0 client.
|
Package rpcclient implements NEO-specific JSON-RPC 2.0 client.
|
||||||
This package is currently in alpha and is subject to change.
|
This package is currently in beta and is subject to change.
|
||||||
|
|
||||||
Client
|
Client
|
||||||
|
|
||||||
|
@ -77,4 +77,4 @@ Unsupported methods
|
||||||
sendtoaddress
|
sendtoaddress
|
||||||
|
|
||||||
*/
|
*/
|
||||||
package client
|
package rpcclient
|
|
@ -1,4 +1,4 @@
|
||||||
package client_test
|
package rpcclient_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -6,14 +6,14 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Example() {
|
func Example() {
|
||||||
endpoint := "http://seed5.bridgeprotocol.io:10332"
|
endpoint := "http://seed5.bridgeprotocol.io:10332"
|
||||||
opts := client.Options{}
|
opts := rpcclient.Options{}
|
||||||
|
|
||||||
c, err := client.New(context.TODO(), endpoint, opts)
|
c, err := rpcclient.New(context.TODO(), endpoint, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
|
@ -10,8 +10,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client/nns"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
// Various non-policy things from native contracts.
|
// Various non-policy things from native contracts.
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/nativenames"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
"github.com/nspcc-dev/neo-go/pkg/core/native/noderoles"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client/nns"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
@ -20,9 +20,9 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -694,9 +694,9 @@ func (c *Client) invokeSomething(method string, p []interface{}, signers []trans
|
||||||
if len(witnesses) != len(signers) {
|
if len(witnesses) != len(signers) {
|
||||||
return nil, fmt.Errorf("number of witnesses should match number of signers, got %d vs %d", len(witnesses), len(signers))
|
return nil, fmt.Errorf("number of witnesses should match number of signers, got %d vs %d", len(witnesses), len(signers))
|
||||||
}
|
}
|
||||||
signersWithWitnesses := make([]request.SignerWithWitness, len(signers))
|
signersWithWitnesses := make([]neorpc.SignerWithWitness, len(signers))
|
||||||
for i := range signersWithWitnesses {
|
for i := range signersWithWitnesses {
|
||||||
signersWithWitnesses[i] = request.SignerWithWitness{
|
signersWithWitnesses[i] = neorpc.SignerWithWitness{
|
||||||
Signer: signers[i],
|
Signer: signers[i],
|
||||||
Witness: witnesses[i],
|
Witness: witnesses[i],
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -27,8 +27,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/fixedn"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server/params"
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/nef"
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -13,9 +13,8 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
)
|
)
|
||||||
|
@ -38,7 +37,7 @@ type WSClient struct {
|
||||||
|
|
||||||
ws *websocket.Conn
|
ws *websocket.Conn
|
||||||
done chan struct{}
|
done chan struct{}
|
||||||
requests chan *request.Raw
|
requests chan *neorpc.Request
|
||||||
shutdown chan struct{}
|
shutdown chan struct{}
|
||||||
closeCalled atomic.Bool
|
closeCalled atomic.Bool
|
||||||
|
|
||||||
|
@ -49,21 +48,21 @@ type WSClient struct {
|
||||||
subscriptions map[string]bool
|
subscriptions map[string]bool
|
||||||
|
|
||||||
respLock sync.RWMutex
|
respLock sync.RWMutex
|
||||||
respChannels map[uint64]chan *response.Raw
|
respChannels map[uint64]chan *neorpc.Response
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notification represents a server-generated notification for client subscriptions.
|
// Notification represents a server-generated notification for client subscriptions.
|
||||||
// Value can be one of block.Block, state.AppExecResult, subscriptions.NotificationEvent
|
// Value can be one of block.Block, state.AppExecResult, state.ContainedNotificationEvent
|
||||||
// transaction.Transaction or subscriptions.NotaryRequestEvent based on Type.
|
// transaction.Transaction or subscriptions.NotaryRequestEvent based on Type.
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
Type response.EventID
|
Type neorpc.EventID
|
||||||
Value interface{}
|
Value interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// requestResponse is a combined type for request and response since we can get
|
// requestResponse is a combined type for request and response since we can get
|
||||||
// any of them here.
|
// any of them here.
|
||||||
type requestResponse struct {
|
type requestResponse struct {
|
||||||
response.Raw
|
neorpc.Response
|
||||||
Method string `json:"method"`
|
Method string `json:"method"`
|
||||||
RawParams []json.RawMessage `json:"params,omitempty"`
|
RawParams []json.RawMessage `json:"params,omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -103,8 +102,8 @@ func NewWS(ctx context.Context, endpoint string, opts Options) (*WSClient, error
|
||||||
shutdown: make(chan struct{}),
|
shutdown: make(chan struct{}),
|
||||||
done: make(chan struct{}),
|
done: make(chan struct{}),
|
||||||
closeCalled: *atomic.NewBool(false),
|
closeCalled: *atomic.NewBool(false),
|
||||||
respChannels: make(map[uint64]chan *response.Raw),
|
respChannels: make(map[uint64]chan *neorpc.Response),
|
||||||
requests: make(chan *request.Raw),
|
requests: make(chan *neorpc.Request),
|
||||||
subscriptions: make(map[string]bool),
|
subscriptions: make(map[string]bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,20 +158,20 @@ readloop:
|
||||||
break readloop
|
break readloop
|
||||||
}
|
}
|
||||||
if rr.ID == nil && rr.Method != "" {
|
if rr.ID == nil && rr.Method != "" {
|
||||||
event, err := response.GetEventIDFromString(rr.Method)
|
event, err := neorpc.GetEventIDFromString(rr.Method)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Bad event received.
|
// Bad event received.
|
||||||
connCloseErr = fmt.Errorf("failed to perse event ID from string %s: %w", rr.Method, err)
|
connCloseErr = fmt.Errorf("failed to perse event ID from string %s: %w", rr.Method, err)
|
||||||
break readloop
|
break readloop
|
||||||
}
|
}
|
||||||
if event != response.MissedEventID && len(rr.RawParams) != 1 {
|
if event != neorpc.MissedEventID && len(rr.RawParams) != 1 {
|
||||||
// Bad event received.
|
// Bad event received.
|
||||||
connCloseErr = fmt.Errorf("bad event received: %s / %d", event, len(rr.RawParams))
|
connCloseErr = fmt.Errorf("bad event received: %s / %d", event, len(rr.RawParams))
|
||||||
break readloop
|
break readloop
|
||||||
}
|
}
|
||||||
var val interface{}
|
var val interface{}
|
||||||
switch event {
|
switch event {
|
||||||
case response.BlockEventID:
|
case neorpc.BlockEventID:
|
||||||
sr, err := c.StateRootInHeader()
|
sr, err := c.StateRootInHeader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Client is not initialized.
|
// Client is not initialized.
|
||||||
|
@ -180,22 +179,22 @@ readloop:
|
||||||
break readloop
|
break readloop
|
||||||
}
|
}
|
||||||
val = block.New(sr)
|
val = block.New(sr)
|
||||||
case response.TransactionEventID:
|
case neorpc.TransactionEventID:
|
||||||
val = &transaction.Transaction{}
|
val = &transaction.Transaction{}
|
||||||
case response.NotificationEventID:
|
case neorpc.NotificationEventID:
|
||||||
val = new(subscriptions.NotificationEvent)
|
val = new(state.ContainedNotificationEvent)
|
||||||
case response.ExecutionEventID:
|
case neorpc.ExecutionEventID:
|
||||||
val = new(state.AppExecResult)
|
val = new(state.AppExecResult)
|
||||||
case response.NotaryRequestEventID:
|
case neorpc.NotaryRequestEventID:
|
||||||
val = new(subscriptions.NotaryRequestEvent)
|
val = new(result.NotaryRequestEvent)
|
||||||
case response.MissedEventID:
|
case neorpc.MissedEventID:
|
||||||
// No value.
|
// No value.
|
||||||
default:
|
default:
|
||||||
// Bad event received.
|
// Bad event received.
|
||||||
connCloseErr = fmt.Errorf("unknown event received: %d", event)
|
connCloseErr = fmt.Errorf("unknown event received: %d", event)
|
||||||
break readloop
|
break readloop
|
||||||
}
|
}
|
||||||
if event != response.MissedEventID {
|
if event != neorpc.MissedEventID {
|
||||||
err = json.Unmarshal(rr.RawParams[0], val)
|
err = json.Unmarshal(rr.RawParams[0], val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Bad event received.
|
// Bad event received.
|
||||||
|
@ -215,7 +214,7 @@ readloop:
|
||||||
connCloseErr = fmt.Errorf("unknown response channel for response %d", id)
|
connCloseErr = fmt.Errorf("unknown response channel for response %d", id)
|
||||||
break readloop // Unknown response (unexpected response ID).
|
break readloop // Unknown response (unexpected response ID).
|
||||||
}
|
}
|
||||||
ch <- &rr.Raw
|
ch <- &rr.Response
|
||||||
} else {
|
} else {
|
||||||
// Malformed response, neither valid request, nor valid response.
|
// Malformed response, neither valid request, nor valid response.
|
||||||
connCloseErr = fmt.Errorf("malformed response")
|
connCloseErr = fmt.Errorf("malformed response")
|
||||||
|
@ -284,14 +283,14 @@ func (c *WSClient) unregisterRespChannel(id uint64) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WSClient) getResponseChannel(id uint64) chan *response.Raw {
|
func (c *WSClient) getResponseChannel(id uint64) chan *neorpc.Response {
|
||||||
c.respLock.RLock()
|
c.respLock.RLock()
|
||||||
defer c.respLock.RUnlock()
|
defer c.respLock.RUnlock()
|
||||||
return c.respChannels[id]
|
return c.respChannels[id]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *WSClient) makeWsRequest(r *request.Raw) (*response.Raw, error) {
|
func (c *WSClient) makeWsRequest(r *neorpc.Request) (*neorpc.Response, error) {
|
||||||
ch := make(chan *response.Raw)
|
ch := make(chan *neorpc.Response)
|
||||||
c.respLock.Lock()
|
c.respLock.Lock()
|
||||||
select {
|
select {
|
||||||
case <-c.done:
|
case <-c.done:
|
||||||
|
@ -354,7 +353,7 @@ func (c *WSClient) performUnsubscription(id string) error {
|
||||||
func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
|
func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
|
||||||
params := []interface{}{"block_added"}
|
params := []interface{}{"block_added"}
|
||||||
if primary != nil {
|
if primary != nil {
|
||||||
params = append(params, request.BlockFilter{Primary: *primary})
|
params = append(params, neorpc.BlockFilter{Primary: *primary})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -365,7 +364,7 @@ func (c *WSClient) SubscribeForNewBlocks(primary *int) (string, error) {
|
||||||
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error) {
|
func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *util.Uint160) (string, error) {
|
||||||
params := []interface{}{"transaction_added"}
|
params := []interface{}{"transaction_added"}
|
||||||
if sender != nil || signer != nil {
|
if sender != nil || signer != nil {
|
||||||
params = append(params, request.TxFilter{Sender: sender, Signer: signer})
|
params = append(params, neorpc.TxFilter{Sender: sender, Signer: signer})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -377,7 +376,7 @@ func (c *WSClient) SubscribeForNewTransactions(sender *util.Uint160, signer *uti
|
||||||
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error) {
|
func (c *WSClient) SubscribeForExecutionNotifications(contract *util.Uint160, name *string) (string, error) {
|
||||||
params := []interface{}{"notification_from_execution"}
|
params := []interface{}{"notification_from_execution"}
|
||||||
if contract != nil || name != nil {
|
if contract != nil || name != nil {
|
||||||
params = append(params, request.NotificationFilter{Contract: contract, Name: name})
|
params = append(params, neorpc.NotificationFilter{Contract: contract, Name: name})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -392,7 +391,7 @@ func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, err
|
||||||
if *state != "HALT" && *state != "FAULT" {
|
if *state != "HALT" && *state != "FAULT" {
|
||||||
return "", errors.New("bad state parameter")
|
return "", errors.New("bad state parameter")
|
||||||
}
|
}
|
||||||
params = append(params, request.ExecutionFilter{State: *state})
|
params = append(params, neorpc.ExecutionFilter{State: *state})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
||||||
|
@ -404,7 +403,7 @@ func (c *WSClient) SubscribeForTransactionExecutions(state *string) (string, err
|
||||||
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error) {
|
func (c *WSClient) SubscribeForNotaryRequests(sender *util.Uint160, mainSigner *util.Uint160) (string, error) {
|
||||||
params := []interface{}{"notary_request_event"}
|
params := []interface{}{"notary_request_event"}
|
||||||
if sender != nil {
|
if sender != nil {
|
||||||
params = append(params, request.TxFilter{Sender: sender, Signer: mainSigner})
|
params = append(params, neorpc.TxFilter{Sender: sender, Signer: mainSigner})
|
||||||
}
|
}
|
||||||
return c.performSubscription(params)
|
return c.performSubscription(params)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package rpcclient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -16,9 +16,9 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
"github.com/nspcc-dev/neo-go/pkg/config/netmode"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server/params"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
|
@ -200,7 +200,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.BlockFilter)
|
filt := new(neorpc.BlockFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, 3, filt.Primary)
|
require.Equal(t, 3, filt.Primary)
|
||||||
},
|
},
|
||||||
|
@ -213,7 +213,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.TxFilter)
|
filt := new(neorpc.TxFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Sender)
|
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Sender)
|
||||||
require.Nil(t, filt.Signer)
|
require.Nil(t, filt.Signer)
|
||||||
|
@ -227,7 +227,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.TxFilter)
|
filt := new(neorpc.TxFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Nil(t, filt.Sender)
|
require.Nil(t, filt.Sender)
|
||||||
require.Equal(t, util.Uint160{0, 42}, *filt.Signer)
|
require.Equal(t, util.Uint160{0, 42}, *filt.Signer)
|
||||||
|
@ -242,7 +242,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.TxFilter)
|
filt := new(neorpc.TxFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Sender)
|
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Sender)
|
||||||
require.Equal(t, util.Uint160{0, 42}, *filt.Signer)
|
require.Equal(t, util.Uint160{0, 42}, *filt.Signer)
|
||||||
|
@ -256,7 +256,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.NotificationFilter)
|
filt := new(neorpc.NotificationFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Contract)
|
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Contract)
|
||||||
require.Nil(t, filt.Name)
|
require.Nil(t, filt.Name)
|
||||||
|
@ -270,7 +270,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.NotificationFilter)
|
filt := new(neorpc.NotificationFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, "my_pretty_notification", *filt.Name)
|
require.Equal(t, "my_pretty_notification", *filt.Name)
|
||||||
require.Nil(t, filt.Contract)
|
require.Nil(t, filt.Contract)
|
||||||
|
@ -285,7 +285,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.NotificationFilter)
|
filt := new(neorpc.NotificationFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Contract)
|
require.Equal(t, util.Uint160{1, 2, 3, 4, 5}, *filt.Contract)
|
||||||
require.Equal(t, "my_pretty_notification", *filt.Name)
|
require.Equal(t, "my_pretty_notification", *filt.Name)
|
||||||
|
@ -299,7 +299,7 @@ func TestWSFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
func(t *testing.T, p *params.Params) {
|
func(t *testing.T, p *params.Params) {
|
||||||
param := p.Value(1)
|
param := p.Value(1)
|
||||||
filt := new(request.ExecutionFilter)
|
filt := new(neorpc.ExecutionFilter)
|
||||||
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
require.NoError(t, json.Unmarshal(param.RawMessage, filt))
|
||||||
require.Equal(t, "FAULT", filt.State)
|
require.Equal(t, "FAULT", filt.State)
|
||||||
},
|
},
|
|
@ -4,13 +4,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RPCClient represent an rpc client for a single node.
|
// RPCClient represent an rpc client for a single node.
|
||||||
type RPCClient struct {
|
type RPCClient struct {
|
||||||
client *client.Client
|
client *rpcclient.Client
|
||||||
addr string
|
addr string
|
||||||
close chan struct{}
|
close chan struct{}
|
||||||
finished chan struct{}
|
finished chan struct{}
|
||||||
|
@ -21,7 +21,7 @@ type RPCClient struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendMethod represents an rpc method for sending data to other nodes.
|
// SendMethod represents an rpc method for sending data to other nodes.
|
||||||
type SendMethod func(*client.Client, []interface{}) error
|
type SendMethod func(*rpcclient.Client, []interface{}) error
|
||||||
|
|
||||||
// NewRPCClient returns a new rpc client for the provided address and method.
|
// NewRPCClient returns a new rpc client for the provided address and method.
|
||||||
func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout time.Duration, ch chan []interface{}) *RPCClient {
|
func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout time.Duration, ch chan []interface{}) *RPCClient {
|
||||||
|
@ -38,7 +38,7 @@ func (r *RPCBroadcaster) NewRPCClient(addr string, method SendMethod, timeout ti
|
||||||
|
|
||||||
func (c *RPCClient) run() {
|
func (c *RPCClient) run() {
|
||||||
// We ignore error as not every node can be available on startup.
|
// We ignore error as not every node can be available on startup.
|
||||||
c.client, _ = client.New(context.Background(), c.addr, client.Options{
|
c.client, _ = rpcclient.New(context.Background(), c.addr, rpcclient.Options{
|
||||||
DialTimeout: c.sendTimeout,
|
DialTimeout: c.sendTimeout,
|
||||||
RequestTimeout: c.sendTimeout,
|
RequestTimeout: c.sendTimeout,
|
||||||
})
|
})
|
||||||
|
@ -50,7 +50,7 @@ run:
|
||||||
case ps := <-c.responses:
|
case ps := <-c.responses:
|
||||||
if c.client == nil {
|
if c.client == nil {
|
||||||
var err error
|
var err error
|
||||||
c.client, err = client.New(context.Background(), c.addr, client.Options{
|
c.client, err = rpcclient.New(context.Background(), c.addr, rpcclient.Options{
|
||||||
DialTimeout: c.sendTimeout,
|
DialTimeout: c.sendTimeout,
|
||||||
RequestTimeout: c.sendTimeout,
|
RequestTimeout: c.sendTimeout,
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/config"
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/helpers/rpcbroadcaster"
|
"github.com/nspcc-dev/neo-go/pkg/services/helpers/rpcbroadcaster"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
"github.com/nspcc-dev/neo-go/pkg/services/oracle"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -33,7 +33,7 @@ func New(cfg config.OracleConfiguration, log *zap.Logger) oracle.Broadcaster {
|
||||||
RPCBroadcaster: *rpcbroadcaster.NewRPCBroadcaster(log, cfg.ResponseTimeout),
|
RPCBroadcaster: *rpcbroadcaster.NewRPCBroadcaster(log, cfg.ResponseTimeout),
|
||||||
}
|
}
|
||||||
for i := range cfg.Nodes {
|
for i := range cfg.Nodes {
|
||||||
r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*client.Client).SubmitRawOracleResponse,
|
r.Clients[cfg.Nodes[i]] = r.NewRPCClient(cfg.Nodes[i], (*rpcclient.Client).SubmitRawOracleResponse,
|
||||||
cfg.ResponseTimeout, make(chan []interface{}, defaultChanCapacity))
|
cfg.ResponseTimeout, make(chan []interface{}, defaultChanCapacity))
|
||||||
}
|
}
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -26,10 +26,10 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network"
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/client/nns"
|
"github.com/nspcc-dev/neo-go/pkg/rpcclient/nns"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/callflag"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/manifest"
|
||||||
|
@ -48,7 +48,7 @@ func TestClient_NEP17(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ func TestAddNetworkFeeCalculateNetworkFee(t *testing.T) {
|
||||||
const extraFee = 10
|
const extraFee = 10
|
||||||
var nonce uint32
|
var nonce uint32
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ func TestCalculateNetworkFee(t *testing.T) {
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
const extraFee = 10
|
const extraFee = 10
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -410,7 +410,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -458,7 +458,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
|
|
||||||
t.Run("good", func(t *testing.T) {
|
t.Run("good", func(t *testing.T) {
|
||||||
t.Run("signer0: sig", func(t *testing.T) {
|
t.Run("signer0: sig", func(t *testing.T) {
|
||||||
h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{
|
h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{
|
||||||
{
|
{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -471,7 +471,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
check(t, h)
|
check(t, h)
|
||||||
})
|
})
|
||||||
t.Run("signer0: sig; signer1: sig", func(t *testing.T) {
|
t.Run("signer0: sig; signer1: sig", func(t *testing.T) {
|
||||||
h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{
|
h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{
|
||||||
{
|
{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -491,7 +491,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
check(t, h)
|
check(t, h)
|
||||||
})
|
})
|
||||||
t.Run("signer0: sig; signer1: contract-based paramless", func(t *testing.T) {
|
t.Run("signer0: sig; signer1: contract-based paramless", func(t *testing.T) {
|
||||||
h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{
|
h, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{
|
||||||
{
|
{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -513,7 +513,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("error", func(t *testing.T) {
|
t.Run("error", func(t *testing.T) {
|
||||||
t.Run("signer0: sig; signer1: contract-based with params", func(t *testing.T) {
|
t.Run("signer0: sig; signer1: contract-based with params", func(t *testing.T) {
|
||||||
_, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{
|
_, err := c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{
|
||||||
{
|
{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -541,7 +541,7 @@ func TestSignAndPushInvocationTx(t *testing.T) {
|
||||||
Parameters: []wallet.ContractParam{{Name: "parameter0", Type: smartcontract.SignatureType}},
|
Parameters: []wallet.ContractParam{{Name: "parameter0", Type: smartcontract.SignatureType}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err = c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []client.SignerAccount{
|
_, err = c.SignAndPushInvocationTx([]byte{byte(opcode.PUSH1)}, acc0, 30, 0, []rpcclient.SignerAccount{
|
||||||
{
|
{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv0.GetScriptHash(),
|
Account: priv0.GetScriptHash(),
|
||||||
|
@ -567,7 +567,7 @@ func TestSignAndPushP2PNotaryRequest(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
acc, err := wallet.NewAccount()
|
acc, err := wallet.NewAccount()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -658,7 +658,7 @@ func TestCalculateNotaryFee(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("client not initialized", func(t *testing.T) {
|
t.Run("client not initialized", func(t *testing.T) {
|
||||||
|
@ -671,7 +671,7 @@ func TestPing(t *testing.T) {
|
||||||
chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t)
|
chain, rpcSrv, httpSrv := initServerWithInMemoryChain(t)
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ func TestCreateTxFromScript(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -715,7 +715,7 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -735,7 +735,7 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
||||||
require.NoError(t, ic.VM.Run())
|
require.NoError(t, ic.VM.Run())
|
||||||
})
|
})
|
||||||
t.Run("none scope", func(t *testing.T) {
|
t.Run("none scope", func(t *testing.T) {
|
||||||
_, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []client.SignerAccount{{
|
_, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []rpcclient.SignerAccount{{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv.PublicKey().GetScriptHash(),
|
Account: priv.PublicKey().GetScriptHash(),
|
||||||
Scopes: transaction.None,
|
Scopes: transaction.None,
|
||||||
|
@ -744,7 +744,7 @@ func TestCreateNEP17TransferTx(t *testing.T) {
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
t.Run("customcontracts scope", func(t *testing.T) {
|
t.Run("customcontracts scope", func(t *testing.T) {
|
||||||
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []client.SignerAccount{{
|
tx, err := c.CreateNEP17TransferTx(acc, util.Uint160{}, gasContractHash, 1000, 0, nil, []rpcclient.SignerAccount{{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: priv.PublicKey().GetScriptHash(),
|
Account: priv.PublicKey().GetScriptHash(),
|
||||||
Scopes: transaction.CustomContracts,
|
Scopes: transaction.CustomContracts,
|
||||||
|
@ -765,7 +765,7 @@ func TestInvokeVerify(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -857,7 +857,7 @@ func TestClient_GetNativeContracts(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -871,7 +871,7 @@ func TestClient_NEP11_ND(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -937,7 +937,7 @@ func TestClient_NEP11_D(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1016,7 +1016,7 @@ func TestClient_NNS(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1088,7 +1088,7 @@ func TestClient_IteratorSessions(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1230,7 +1230,7 @@ func TestClient_GetNotaryServiceFeePerKey(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1245,7 +1245,7 @@ func TestClient_GetOraclePrice(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1260,7 +1260,7 @@ func TestClient_InvokeAndPackIteratorResults(t *testing.T) {
|
||||||
defer chain.Close()
|
defer chain.Close()
|
||||||
defer rpcSrv.Shutdown()
|
defer rpcSrv.Shutdown()
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1319,7 +1319,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) {
|
||||||
// storageItemsCount is the amount of storage items stored in Storage contract, it's hard-coded in the contract code.
|
// storageItemsCount is the amount of storage items stored in Storage contract, it's hard-coded in the contract code.
|
||||||
const storageItemsCount = 255
|
const storageItemsCount = 255
|
||||||
|
|
||||||
checkSessionEnabled := func(t *testing.T, c *client.Client) {
|
checkSessionEnabled := func(t *testing.T, c *rpcclient.Client) {
|
||||||
// We expect Iterator with designated ID to be presented on stack. It should be possible to retrieve its values via `traverseiterator` call.
|
// We expect Iterator with designated ID to be presented on stack. It should be possible to retrieve its values via `traverseiterator` call.
|
||||||
res, err := c.InvokeFunction(storageHash, "iterateOverValues", []smartcontract.Parameter{}, nil)
|
res, err := c.InvokeFunction(storageHash, "iterateOverValues", []smartcontract.Parameter{}, nil)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -1347,7 +1347,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) {
|
||||||
require.NoError(t, chain.AddBlock(b))
|
require.NoError(t, chain.AddBlock(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1386,7 +1386,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) {
|
||||||
require.NoError(t, chain.AddBlock(b))
|
require.NoError(t, chain.AddBlock(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
||||||
|
@ -1400,7 +1400,7 @@ func TestClient_Iterator_SessionConfigVariations(t *testing.T) {
|
||||||
require.NoError(t, chain.AddBlock(b))
|
require.NoError(t, chain.AddBlock(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := client.New(context.Background(), httpSrv.URL, client.Options{})
|
c, err := rpcclient.New(context.Background(), httpSrv.URL, rpcclient.Options{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, c.Init())
|
require.NoError(t, c.Init())
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// abstractResult is an interface which represents either single JSON-RPC 2.0 response
|
// abstractResult is an interface which represents either single JSON-RPC 2.0 response
|
||||||
// or batch JSON-RPC 2.0 response.
|
// or batch JSON-RPC 2.0 response.
|
||||||
type abstractResult interface {
|
type abstractResult interface {
|
||||||
RunForErrors(f func(jsonErr *response.Error))
|
RunForErrors(f func(jsonErr *neorpc.Error))
|
||||||
}
|
}
|
||||||
|
|
||||||
// abstract represents abstract JSON-RPC 2.0 response. It is used as a server-side response
|
// abstract represents abstract JSON-RPC 2.0 response. It is used as a server-side response
|
||||||
// representation.
|
// representation.
|
||||||
type abstract struct {
|
type abstract struct {
|
||||||
response.Header
|
neorpc.Header
|
||||||
Error *response.Error `json:"error,omitempty"`
|
Error *neorpc.Error `json:"error,omitempty"`
|
||||||
Result interface{} `json:"result,omitempty"`
|
Result interface{} `json:"result,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunForErrors implements abstractResult interface.
|
// RunForErrors implements abstractResult interface.
|
||||||
func (a abstract) RunForErrors(f func(jsonErr *response.Error)) {
|
func (a abstract) RunForErrors(f func(jsonErr *neorpc.Error)) {
|
||||||
if a.Error != nil {
|
if a.Error != nil {
|
||||||
f(a.Error)
|
f(a.Error)
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ func (a abstract) RunForErrors(f func(jsonErr *response.Error)) {
|
||||||
type abstractBatch []abstract
|
type abstractBatch []abstract
|
||||||
|
|
||||||
// RunForErrors implements abstractResult interface.
|
// RunForErrors implements abstractResult interface.
|
||||||
func (ab abstractBatch) RunForErrors(f func(jsonErr *response.Error)) {
|
func (ab abstractBatch) RunForErrors(f func(jsonErr *neorpc.Error)) {
|
||||||
for _, a := range ab {
|
for _, a := range ab {
|
||||||
if a.Error != nil {
|
if a.Error != nil {
|
||||||
f(a.Error)
|
f(a.Error)
|
||||||
|
@ -39,16 +39,16 @@ func (ab abstractBatch) RunForErrors(f func(jsonErr *response.Error)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHTTPCodeForError(respErr *response.Error) int {
|
func getHTTPCodeForError(respErr *neorpc.Error) int {
|
||||||
var httpCode int
|
var httpCode int
|
||||||
switch respErr.Code {
|
switch respErr.Code {
|
||||||
case response.BadRequestCode:
|
case neorpc.BadRequestCode:
|
||||||
httpCode = http.StatusBadRequest
|
httpCode = http.StatusBadRequest
|
||||||
case response.InvalidRequestCode, response.RPCErrorCode, response.InvalidParamsCode:
|
case neorpc.InvalidRequestCode, neorpc.RPCErrorCode, neorpc.InvalidParamsCode:
|
||||||
httpCode = http.StatusUnprocessableEntity
|
httpCode = http.StatusUnprocessableEntity
|
||||||
case response.MethodNotFoundCode:
|
case neorpc.MethodNotFoundCode:
|
||||||
httpCode = http.StatusMethodNotAllowed
|
httpCode = http.StatusMethodNotAllowed
|
||||||
case response.InternalServerErrorCode:
|
case neorpc.InternalServerErrorCode:
|
||||||
httpCode = http.StatusInternalServerError
|
httpCode = http.StatusInternalServerError
|
||||||
default:
|
default:
|
||||||
httpCode = http.StatusUnprocessableEntity
|
httpCode = http.StatusUnprocessableEntity
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
@ -380,13 +380,13 @@ func (p *Param) GetBytesBase64() ([]byte, error) {
|
||||||
return base64.StdEncoding.DecodeString(s)
|
return base64.StdEncoding.DecodeString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSignerWithWitness returns a request.SignerWithWitness value of the parameter.
|
// GetSignerWithWitness returns a neorpc.SignerWithWitness value of the parameter.
|
||||||
func (p *Param) GetSignerWithWitness() (request.SignerWithWitness, error) {
|
func (p *Param) GetSignerWithWitness() (neorpc.SignerWithWitness, error) {
|
||||||
// This one doesn't need to be cached, it's used only once.
|
// This one doesn't need to be cached, it's used only once.
|
||||||
c := request.SignerWithWitness{}
|
c := neorpc.SignerWithWitness{}
|
||||||
err := json.Unmarshal(p.RawMessage, &c)
|
err := json.Unmarshal(p.RawMessage, &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return request.SignerWithWitness{}, fmt.Errorf("not a signer: %w", err)
|
return neorpc.SignerWithWitness{}, fmt.Errorf("not a signer: %w", err)
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -155,7 +155,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expectedAcc, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569")
|
expectedAcc, err := util.Uint160DecodeStringLE("cadb3dc2faa3ef14a13b619c9a43124755aa2569")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, request.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc}}, actual)
|
require.Equal(t, neorpc.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc}}, actual)
|
||||||
},
|
},
|
||||||
expectedRawMessage: []byte(`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`),
|
expectedRawMessage: []byte(`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`),
|
||||||
},
|
},
|
||||||
|
@ -165,7 +165,7 @@ func TestParam_UnmarshalJSON(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
expectedAcc, err := address.StringToUint160("NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag")
|
expectedAcc, err := address.StringToUint160("NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, request.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc, Scopes: transaction.Global}}, actual)
|
require.Equal(t, neorpc.SignerWithWitness{Signer: transaction.Signer{Account: expectedAcc, Scopes: transaction.Global}}, actual)
|
||||||
},
|
},
|
||||||
expectedRawMessage: []byte(`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`),
|
expectedRawMessage: []byte(`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`),
|
||||||
},
|
},
|
||||||
|
@ -244,21 +244,21 @@ func TestGetWitness(t *testing.T) {
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
raw string
|
raw string
|
||||||
expected request.SignerWithWitness
|
expected neorpc.SignerWithWitness
|
||||||
}{
|
}{
|
||||||
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`, request.SignerWithWitness{
|
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569"}`, neorpc.SignerWithWitness{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: accountHash,
|
Account: accountHash,
|
||||||
Scopes: transaction.None,
|
Scopes: transaction.None,
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`, request.SignerWithWitness{
|
{`{"account": "NYxb4fSZVKAz8YsgaPK2WkT3KcAE9b3Vag", "scopes": "Global"}`, neorpc.SignerWithWitness{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: addrHash,
|
Account: addrHash,
|
||||||
Scopes: transaction.Global,
|
Scopes: transaction.Global,
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}`, request.SignerWithWitness{
|
{`{"account": "0xcadb3dc2faa3ef14a13b619c9a43124755aa2569", "scopes": "Global"}`, neorpc.SignerWithWitness{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: accountHash,
|
Account: accountHash,
|
||||||
Scopes: transaction.Global,
|
Scopes: transaction.Global,
|
||||||
|
@ -405,7 +405,7 @@ func TestParamGetBytesBase64(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParamGetSigner(t *testing.T) {
|
func TestParamGetSigner(t *testing.T) {
|
||||||
c := request.SignerWithWitness{
|
c := neorpc.SignerWithWitness{
|
||||||
Signer: transaction.Signer{
|
Signer: transaction.Signer{
|
||||||
Account: util.Uint160{1, 2, 3, 4},
|
Account: util.Uint160{1, 2, 3, 4},
|
||||||
Scopes: transaction.Global,
|
Scopes: transaction.Global,
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -106,6 +106,6 @@ func NewRequest() *Request {
|
||||||
// NewIn creates a new In struct.
|
// NewIn creates a new In struct.
|
||||||
func NewIn() *In {
|
func NewIn() *In {
|
||||||
return &In{
|
return &In{
|
||||||
JSONRPC: request.JSONRPCVersion,
|
JSONRPC: neorpc.JSONRPCVersion,
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -25,7 +25,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
notaryPath = "../../services/notary/testdata/notary1.json"
|
notaryPath = "../notary/testdata/notary1.json"
|
||||||
notaryPass = "one"
|
notaryPass = "one"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ func getUnitTestChain(t testing.TB, enableOracle bool, enableNotary bool, disabl
|
||||||
if enableOracle {
|
if enableOracle {
|
||||||
cfg.ApplicationConfiguration.Oracle.Enabled = true
|
cfg.ApplicationConfiguration.Oracle.Enabled = true
|
||||||
cfg.ApplicationConfiguration.Oracle.UnlockWallet = config.Wallet{
|
cfg.ApplicationConfiguration.Oracle.UnlockWallet = config.Wallet{
|
||||||
Path: "../../services/oracle/testdata/oracle1.json",
|
Path: "../oracle/testdata/oracle1.json",
|
||||||
Password: "one",
|
Password: "one",
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -33,12 +33,12 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network"
|
"github.com/nspcc-dev/neo-go/pkg/network"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
"github.com/nspcc-dev/neo-go/pkg/network/payload"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/server/params"
|
|
||||||
rpc2 "github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster"
|
rpc2 "github.com/nspcc-dev/neo-go/pkg/services/oracle/broadcaster"
|
||||||
|
"github.com/nspcc-dev/neo-go/pkg/services/rpcsrv/params"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract/trigger"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
"github.com/nspcc-dev/neo-go/pkg/vm/emit"
|
||||||
|
@ -1928,11 +1928,11 @@ func testRPCProtocol(t *testing.T, doRPCCall func(string, string, *testing.T) []
|
||||||
}
|
}
|
||||||
resultRPC = `[` + resultRPC[:len(resultRPC)-1] + `]`
|
resultRPC = `[` + resultRPC[:len(resultRPC)-1] + `]`
|
||||||
body := doRPCCall(resultRPC, httpSrv.URL, t)
|
body := doRPCCall(resultRPC, httpSrv.URL, t)
|
||||||
var responses []response.Raw
|
var responses []neorpc.Response
|
||||||
err := json.Unmarshal(body, &responses)
|
err := json.Unmarshal(body, &responses)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
for i, tc := range cases {
|
for i, tc := range cases {
|
||||||
var resp response.Raw
|
var resp neorpc.Response
|
||||||
for _, r := range responses {
|
for _, r := range responses {
|
||||||
if bytes.Equal(r.ID, []byte(strconv.Itoa(i))) {
|
if bytes.Equal(r.ID, []byte(strconv.Itoa(i))) {
|
||||||
resp = r
|
resp = r
|
||||||
|
@ -2478,7 +2478,7 @@ func (tc rpcTestCase) getResultPair(e *executor) (expected interface{}, res inte
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkErrGetResult(t *testing.T, body []byte, expectingFail bool, expectedErr ...string) json.RawMessage {
|
func checkErrGetResult(t *testing.T, body []byte, expectingFail bool, expectedErr ...string) json.RawMessage {
|
||||||
var resp response.Raw
|
var resp neorpc.Response
|
||||||
err := json.Unmarshal(body, &resp)
|
err := json.Unmarshal(body, &resp)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
if expectingFail {
|
if expectingFail {
|
||||||
|
@ -2495,7 +2495,7 @@ func checkErrGetResult(t *testing.T, body []byte, expectingFail bool, expectedEr
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkErrGetBatchResult(t *testing.T, body []byte, expectingFail bool) json.RawMessage {
|
func checkErrGetBatchResult(t *testing.T, body []byte, expectingFail bool) json.RawMessage {
|
||||||
var resp []response.Raw
|
var resp []neorpc.Response
|
||||||
err := json.Unmarshal(body, &resp)
|
err := json.Unmarshal(body, &resp)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, 1, len(resp))
|
require.Equal(t, 1, len(resp))
|
|
@ -1,13 +1,12 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
"github.com/nspcc-dev/neo-go/pkg/core/block"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
"github.com/nspcc-dev/neo-go/pkg/core/state"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/request"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result/subscriptions"
|
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ type (
|
||||||
feeds [maxFeeds]feed
|
feeds [maxFeeds]feed
|
||||||
}
|
}
|
||||||
feed struct {
|
feed struct {
|
||||||
event response.EventID
|
event neorpc.EventID
|
||||||
filter interface{}
|
filter interface{}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -44,7 +43,7 @@ const (
|
||||||
notificationBufSize = 1024
|
notificationBufSize = 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *feed) Matches(r *response.Notification) bool {
|
func (f *feed) Matches(r *neorpc.Notification) bool {
|
||||||
if r.Event != f.event {
|
if r.Event != f.event {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -52,12 +51,12 @@ func (f *feed) Matches(r *response.Notification) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
switch f.event {
|
switch f.event {
|
||||||
case response.BlockEventID:
|
case neorpc.BlockEventID:
|
||||||
filt := f.filter.(request.BlockFilter)
|
filt := f.filter.(neorpc.BlockFilter)
|
||||||
b := r.Payload[0].(*block.Block)
|
b := r.Payload[0].(*block.Block)
|
||||||
return int(b.PrimaryIndex) == filt.Primary
|
return int(b.PrimaryIndex) == filt.Primary
|
||||||
case response.TransactionEventID:
|
case neorpc.TransactionEventID:
|
||||||
filt := f.filter.(request.TxFilter)
|
filt := f.filter.(neorpc.TxFilter)
|
||||||
tx := r.Payload[0].(*transaction.Transaction)
|
tx := r.Payload[0].(*transaction.Transaction)
|
||||||
senderOK := filt.Sender == nil || tx.Sender().Equals(*filt.Sender)
|
senderOK := filt.Sender == nil || tx.Sender().Equals(*filt.Sender)
|
||||||
signerOK := true
|
signerOK := true
|
||||||
|
@ -71,19 +70,19 @@ func (f *feed) Matches(r *response.Notification) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return senderOK && signerOK
|
return senderOK && signerOK
|
||||||
case response.NotificationEventID:
|
case neorpc.NotificationEventID:
|
||||||
filt := f.filter.(request.NotificationFilter)
|
filt := f.filter.(neorpc.NotificationFilter)
|
||||||
notification := r.Payload[0].(*subscriptions.NotificationEvent)
|
notification := r.Payload[0].(*state.ContainedNotificationEvent)
|
||||||
hashOk := filt.Contract == nil || notification.ScriptHash.Equals(*filt.Contract)
|
hashOk := filt.Contract == nil || notification.ScriptHash.Equals(*filt.Contract)
|
||||||
nameOk := filt.Name == nil || notification.Name == *filt.Name
|
nameOk := filt.Name == nil || notification.Name == *filt.Name
|
||||||
return hashOk && nameOk
|
return hashOk && nameOk
|
||||||
case response.ExecutionEventID:
|
case neorpc.ExecutionEventID:
|
||||||
filt := f.filter.(request.ExecutionFilter)
|
filt := f.filter.(neorpc.ExecutionFilter)
|
||||||
applog := r.Payload[0].(*state.AppExecResult)
|
applog := r.Payload[0].(*state.AppExecResult)
|
||||||
return applog.VMState.String() == filt.State
|
return applog.VMState.String() == filt.State
|
||||||
case response.NotaryRequestEventID:
|
case neorpc.NotaryRequestEventID:
|
||||||
filt := f.filter.(request.TxFilter)
|
filt := f.filter.(neorpc.TxFilter)
|
||||||
req := r.Payload[0].(*subscriptions.NotaryRequestEvent)
|
req := r.Payload[0].(*result.NotaryRequestEvent)
|
||||||
senderOk := filt.Sender == nil || req.NotaryRequest.FallbackTransaction.Signers[1].Account == *filt.Sender
|
senderOk := filt.Sender == nil || req.NotaryRequest.FallbackTransaction.Signers[1].Account == *filt.Sender
|
||||||
signerOK := true
|
signerOK := true
|
||||||
if filt.Signer != nil {
|
if filt.Signer != nil {
|
|
@ -1,4 +1,4 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/nspcc-dev/neo-go/internal/testchain"
|
"github.com/nspcc-dev/neo-go/internal/testchain"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
"github.com/nspcc-dev/neo-go/pkg/core"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
)
|
)
|
||||||
|
@ -36,8 +36,8 @@ func wsReader(t *testing.T, ws *websocket.Conn, msgCh chan<- []byte, isFinished
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []byte) *response.Raw {
|
func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []byte) *neorpc.Response {
|
||||||
var resp = new(response.Raw)
|
var resp = new(neorpc.Response)
|
||||||
|
|
||||||
require.NoError(t, ws.SetWriteDeadline(time.Now().Add(time.Second)))
|
require.NoError(t, ws.SetWriteDeadline(time.Now().Add(time.Second)))
|
||||||
require.NoError(t, ws.WriteMessage(websocket.TextMessage, []byte(msg)))
|
require.NoError(t, ws.WriteMessage(websocket.TextMessage, []byte(msg)))
|
||||||
|
@ -47,8 +47,8 @@ func callWSGetRaw(t *testing.T, ws *websocket.Conn, msg string, respCh <-chan []
|
||||||
return resp
|
return resp
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNotification(t *testing.T, respCh <-chan []byte) *response.Notification {
|
func getNotification(t *testing.T, respCh <-chan []byte) *neorpc.Notification {
|
||||||
var resp = new(response.Notification)
|
var resp = new(neorpc.Notification)
|
||||||
body := <-respCh
|
body := <-respCh
|
||||||
require.NoError(t, json.Unmarshal(body, resp))
|
require.NoError(t, json.Unmarshal(body, resp))
|
||||||
return resp
|
return resp
|
||||||
|
@ -107,10 +107,10 @@ func TestSubscriptions(t *testing.T) {
|
||||||
for _, b := range getTestBlocks(t) {
|
for _, b := range getTestBlocks(t) {
|
||||||
require.NoError(t, chain.AddBlock(b))
|
require.NoError(t, chain.AddBlock(b))
|
||||||
resp := getNotification(t, respMsgs)
|
resp := getNotification(t, respMsgs)
|
||||||
require.Equal(t, response.ExecutionEventID, resp.Event)
|
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||||
for {
|
for {
|
||||||
resp = getNotification(t, respMsgs)
|
resp = getNotification(t, respMsgs)
|
||||||
if resp.Event != response.NotificationEventID {
|
if resp.Event != neorpc.NotificationEventID {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,25 +118,25 @@ func TestSubscriptions(t *testing.T) {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
resp = getNotification(t, respMsgs)
|
resp = getNotification(t, respMsgs)
|
||||||
}
|
}
|
||||||
require.Equal(t, response.ExecutionEventID, resp.Event)
|
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||||
for {
|
for {
|
||||||
resp := getNotification(t, respMsgs)
|
resp := getNotification(t, respMsgs)
|
||||||
if resp.Event == response.NotificationEventID {
|
if resp.Event == neorpc.NotificationEventID {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
require.Equal(t, response.TransactionEventID, resp.Event)
|
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp = getNotification(t, respMsgs)
|
resp = getNotification(t, respMsgs)
|
||||||
require.Equal(t, response.ExecutionEventID, resp.Event)
|
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||||
for {
|
for {
|
||||||
resp = getNotification(t, respMsgs)
|
resp = getNotification(t, respMsgs)
|
||||||
if resp.Event != response.NotificationEventID {
|
if resp.Event != neorpc.NotificationEventID {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
require.Equal(t, response.BlockEventID, resp.Event)
|
require.Equal(t, neorpc.BlockEventID, resp.Event)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should manually add NotaryRequest to test notification.
|
// We should manually add NotaryRequest to test notification.
|
||||||
|
@ -145,7 +145,7 @@ func TestSubscriptions(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for {
|
for {
|
||||||
resp := getNotification(t, respMsgs)
|
resp := getNotification(t, respMsgs)
|
||||||
if resp.Event == response.NotaryRequestEventID {
|
if resp.Event == neorpc.NotaryRequestEventID {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,22 +163,22 @@ func TestFilteredSubscriptions(t *testing.T) {
|
||||||
|
|
||||||
var cases = map[string]struct {
|
var cases = map[string]struct {
|
||||||
params string
|
params string
|
||||||
check func(*testing.T, *response.Notification)
|
check func(*testing.T, *neorpc.Notification)
|
||||||
}{
|
}{
|
||||||
"tx matching sender": {
|
"tx matching sender": {
|
||||||
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `"}]`,
|
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.TransactionEventID, resp.Event)
|
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||||
sender := rmap["sender"].(string)
|
sender := rmap["sender"].(string)
|
||||||
require.Equal(t, address.Uint160ToString(goodSender), sender)
|
require.Equal(t, address.Uint160ToString(goodSender), sender)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"tx matching signer": {
|
"tx matching signer": {
|
||||||
params: `["transaction_added", {"signer":"` + goodSender.StringLE() + `"}]`,
|
params: `["transaction_added", {"signer":"` + goodSender.StringLE() + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.TransactionEventID, resp.Event)
|
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||||
signers := rmap["signers"].([]interface{})
|
signers := rmap["signers"].([]interface{})
|
||||||
signer0 := signers[0].(map[string]interface{})
|
signer0 := signers[0].(map[string]interface{})
|
||||||
signer0acc := signer0["account"].(string)
|
signer0acc := signer0["account"].(string)
|
||||||
|
@ -187,9 +187,9 @@ func TestFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
"tx matching sender and signer": {
|
"tx matching sender and signer": {
|
||||||
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
|
params: `["transaction_added", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.TransactionEventID, resp.Event)
|
require.Equal(t, neorpc.TransactionEventID, resp.Event)
|
||||||
sender := rmap["sender"].(string)
|
sender := rmap["sender"].(string)
|
||||||
require.Equal(t, address.Uint160ToString(goodSender), sender)
|
require.Equal(t, address.Uint160ToString(goodSender), sender)
|
||||||
signers := rmap["signers"].([]interface{})
|
signers := rmap["signers"].([]interface{})
|
||||||
|
@ -200,27 +200,27 @@ func TestFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
"notification matching contract hash": {
|
"notification matching contract hash": {
|
||||||
params: `["notification_from_execution", {"contract":"` + testContractHash + `"}]`,
|
params: `["notification_from_execution", {"contract":"` + testContractHash + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.NotificationEventID, resp.Event)
|
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||||
c := rmap["contract"].(string)
|
c := rmap["contract"].(string)
|
||||||
require.Equal(t, "0x"+testContractHash, c)
|
require.Equal(t, "0x"+testContractHash, c)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"notification matching name": {
|
"notification matching name": {
|
||||||
params: `["notification_from_execution", {"name":"my_pretty_notification"}]`,
|
params: `["notification_from_execution", {"name":"my_pretty_notification"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.NotificationEventID, resp.Event)
|
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||||
n := rmap["name"].(string)
|
n := rmap["name"].(string)
|
||||||
require.Equal(t, "my_pretty_notification", n)
|
require.Equal(t, "my_pretty_notification", n)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"notification matching contract hash and name": {
|
"notification matching contract hash and name": {
|
||||||
params: `["notification_from_execution", {"contract":"` + testContractHash + `", "name":"my_pretty_notification"}]`,
|
params: `["notification_from_execution", {"contract":"` + testContractHash + `", "name":"my_pretty_notification"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.NotificationEventID, resp.Event)
|
require.Equal(t, neorpc.NotificationEventID, resp.Event)
|
||||||
c := rmap["contract"].(string)
|
c := rmap["contract"].(string)
|
||||||
require.Equal(t, "0x"+testContractHash, c)
|
require.Equal(t, "0x"+testContractHash, c)
|
||||||
n := rmap["name"].(string)
|
n := rmap["name"].(string)
|
||||||
|
@ -229,28 +229,28 @@ func TestFilteredSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
"execution matching": {
|
"execution matching": {
|
||||||
params: `["transaction_executed", {"state":"HALT"}]`,
|
params: `["transaction_executed", {"state":"HALT"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.ExecutionEventID, resp.Event)
|
require.Equal(t, neorpc.ExecutionEventID, resp.Event)
|
||||||
st := rmap["vmstate"].(string)
|
st := rmap["vmstate"].(string)
|
||||||
require.Equal(t, "HALT", st)
|
require.Equal(t, "HALT", st)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"tx non-matching": {
|
"tx non-matching": {
|
||||||
params: `["transaction_added", {"sender":"00112233445566778899aabbccddeeff00112233"}]`,
|
params: `["transaction_added", {"sender":"00112233445566778899aabbccddeeff00112233"}]`,
|
||||||
check: func(t *testing.T, _ *response.Notification) {
|
check: func(t *testing.T, _ *neorpc.Notification) {
|
||||||
t.Fatal("unexpected match for EnrollmentTransaction")
|
t.Fatal("unexpected match for EnrollmentTransaction")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"notification non-matching": {
|
"notification non-matching": {
|
||||||
params: `["notification_from_execution", {"contract":"00112233445566778899aabbccddeeff00112233"}]`,
|
params: `["notification_from_execution", {"contract":"00112233445566778899aabbccddeeff00112233"}]`,
|
||||||
check: func(t *testing.T, _ *response.Notification) {
|
check: func(t *testing.T, _ *neorpc.Notification) {
|
||||||
t.Fatal("unexpected match for contract 00112233445566778899aabbccddeeff00112233")
|
t.Fatal("unexpected match for contract 00112233445566778899aabbccddeeff00112233")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"execution non-matching": {
|
"execution non-matching": {
|
||||||
params: `["transaction_executed", {"state":"FAULT"}]`,
|
params: `["transaction_executed", {"state":"FAULT"}]`,
|
||||||
check: func(t *testing.T, _ *response.Notification) {
|
check: func(t *testing.T, _ *neorpc.Notification) {
|
||||||
t.Fatal("unexpected match for faulted execution")
|
t.Fatal("unexpected match for faulted execution")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -276,7 +276,7 @@ func TestFilteredSubscriptions(t *testing.T) {
|
||||||
for {
|
for {
|
||||||
resp := getNotification(t, respMsgs)
|
resp := getNotification(t, respMsgs)
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
if resp.Event == response.BlockEventID {
|
if resp.Event == neorpc.BlockEventID {
|
||||||
index := rmap["index"].(float64)
|
index := rmap["index"].(float64)
|
||||||
if uint32(index) == lastBlock {
|
if uint32(index) == lastBlock {
|
||||||
break
|
break
|
||||||
|
@ -302,13 +302,13 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
|
||||||
|
|
||||||
var cases = map[string]struct {
|
var cases = map[string]struct {
|
||||||
params string
|
params string
|
||||||
check func(*testing.T, *response.Notification)
|
check func(*testing.T, *neorpc.Notification)
|
||||||
}{
|
}{
|
||||||
"matching sender": {
|
"matching sender": {
|
||||||
params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `"}]`,
|
params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.NotaryRequestEventID, resp.Event)
|
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
|
||||||
require.Equal(t, "added", rmap["type"].(string))
|
require.Equal(t, "added", rmap["type"].(string))
|
||||||
req := rmap["notaryrequest"].(map[string]interface{})
|
req := rmap["notaryrequest"].(map[string]interface{})
|
||||||
fbTx := req["fallbacktx"].(map[string]interface{})
|
fbTx := req["fallbacktx"].(map[string]interface{})
|
||||||
|
@ -318,9 +318,9 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
"matching signer": {
|
"matching signer": {
|
||||||
params: `["notary_request_event", {"signer":"` + goodSender.StringLE() + `"}]`,
|
params: `["notary_request_event", {"signer":"` + goodSender.StringLE() + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.NotaryRequestEventID, resp.Event)
|
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
|
||||||
require.Equal(t, "added", rmap["type"].(string))
|
require.Equal(t, "added", rmap["type"].(string))
|
||||||
req := rmap["notaryrequest"].(map[string]interface{})
|
req := rmap["notaryrequest"].(map[string]interface{})
|
||||||
mainTx := req["maintx"].(map[string]interface{})
|
mainTx := req["maintx"].(map[string]interface{})
|
||||||
|
@ -332,9 +332,9 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
|
||||||
},
|
},
|
||||||
"matching sender and signer": {
|
"matching sender and signer": {
|
||||||
params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
|
params: `["notary_request_event", {"sender":"` + goodSender.StringLE() + `", "signer":"` + goodSender.StringLE() + `"}]`,
|
||||||
check: func(t *testing.T, resp *response.Notification) {
|
check: func(t *testing.T, resp *neorpc.Notification) {
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
require.Equal(t, response.NotaryRequestEventID, resp.Event)
|
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
|
||||||
require.Equal(t, "added", rmap["type"].(string))
|
require.Equal(t, "added", rmap["type"].(string))
|
||||||
req := rmap["notaryrequest"].(map[string]interface{})
|
req := rmap["notaryrequest"].(map[string]interface{})
|
||||||
mainTx := req["maintx"].(map[string]interface{})
|
mainTx := req["maintx"].(map[string]interface{})
|
||||||
|
@ -370,7 +370,7 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
nonce++
|
nonce++
|
||||||
|
|
||||||
var resp = new(response.Notification)
|
var resp = new(neorpc.Notification)
|
||||||
select {
|
select {
|
||||||
case body := <-respMsgs:
|
case body := <-respMsgs:
|
||||||
require.NoError(t, json.Unmarshal(body, resp))
|
require.NoError(t, json.Unmarshal(body, resp))
|
||||||
|
@ -378,7 +378,7 @@ func TestFilteredNotaryRequestSubscriptions(t *testing.T) {
|
||||||
t.Fatal("timeout waiting for event")
|
t.Fatal("timeout waiting for event")
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, response.NotaryRequestEventID, resp.Event)
|
require.Equal(t, neorpc.NotaryRequestEventID, resp.Event)
|
||||||
this.check(t, resp)
|
this.check(t, resp)
|
||||||
|
|
||||||
callUnsubscribe(t, c, respMsgs, subID)
|
callUnsubscribe(t, c, respMsgs, subID)
|
||||||
|
@ -410,7 +410,7 @@ func TestFilteredBlockSubscriptions(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < expectedCnt; i++ {
|
for i := 0; i < expectedCnt; i++ {
|
||||||
var resp = new(response.Notification)
|
var resp = new(neorpc.Notification)
|
||||||
select {
|
select {
|
||||||
case body := <-respMsgs:
|
case body := <-respMsgs:
|
||||||
require.NoError(t, json.Unmarshal(body, resp))
|
require.NoError(t, json.Unmarshal(body, resp))
|
||||||
|
@ -418,7 +418,7 @@ func TestFilteredBlockSubscriptions(t *testing.T) {
|
||||||
t.Fatal("timeout waiting for event")
|
t.Fatal("timeout waiting for event")
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, response.BlockEventID, resp.Event)
|
require.Equal(t, neorpc.BlockEventID, resp.Event)
|
||||||
rmap := resp.Payload[0].(map[string]interface{})
|
rmap := resp.Payload[0].(map[string]interface{})
|
||||||
primary := rmap["primary"].(float64)
|
primary := rmap["primary"].(float64)
|
||||||
require.Equal(t, 3, int(primary))
|
require.Equal(t, 3, int(primary))
|
||||||
|
@ -565,8 +565,8 @@ func TestSubscriptionOverflow(t *testing.T) {
|
||||||
}
|
}
|
||||||
for i := 0; i < blockCnt; i++ {
|
for i := 0; i < blockCnt; i++ {
|
||||||
resp := getNotification(t, respMsgs)
|
resp := getNotification(t, respMsgs)
|
||||||
if resp.Event != response.BlockEventID {
|
if resp.Event != neorpc.BlockEventID {
|
||||||
require.Equal(t, response.MissedEventID, resp.Event)
|
require.Equal(t, neorpc.MissedEventID, resp.Event)
|
||||||
receivedMiss = true
|
receivedMiss = true
|
||||||
break
|
break
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package server
|
package rpcsrv
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/rpc/response/result"
|
"github.com/nspcc-dev/neo-go/pkg/neorpc/result"
|
||||||
)
|
)
|
||||||
|
|
||||||
// tokenTransfers is a generic type used to represent NEP-11 and NEP-17 transfers.
|
// tokenTransfers is a generic type used to represent NEP-11 and NEP-17 transfers.
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue