Commit graph

178 commits

Author SHA1 Message Date
Anna Shaleva
5811687836 rpc: fix bug in Actor's waiter
Execution events are followed by block events, not vise versa, thus,
we can wait until VUB block to be accepted to be sure that
transaction wasn't accepted to chain.
2022-10-26 15:32:54 +03:00
Anna Shaleva
0a5905390c rpc: refactor WSClient subscriptions API
Make it more specific, close #2756.
2022-10-26 15:32:54 +03:00
Anna Shaleva
3cccc89dac rpc: add Wait wrapper to Notary actor 2022-10-24 06:09:36 +03:00
Anna Shaleva
1a6f1c805c rpc: fix race in TestWSClientEvents
```
2022-10-21T08:59:45.2219797Z === RUN   TestWSClientEvents/default_ntf_channel
2022-10-21T08:59:45.2219901Z ==================
2022-10-21T08:59:45.2220017Z WARNING: DATA RACE
2022-10-21T08:59:45.2220177Z Write at 0x00c000c82778 by goroutine 371:
2022-10-21T08:59:45.2220580Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.TestWSClientEvents.func2()
2022-10-21T08:59:45.2221112Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/wsclient_test.go:171 +0x1c4
2022-10-21T08:59:45.2221244Z   testing.tRunner()
2022-10-21T08:59:45.2221617Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1439 +0x213
2022-10-21T08:59:45.2221759Z   testing.(*T).Run.func1()
2022-10-21T08:59:45.2222124Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x47
2022-10-21T08:59:45.2222138Z
2022-10-21T08:59:45.2222308Z Previous read at 0x00c000c82778 by goroutine 37:
2022-10-21T08:59:45.2222694Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.(*Client).StateRootInHeader()
2022-10-21T08:59:45.2223151Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/rpc.go:1104 +0xb0
2022-10-21T08:59:45.2223482Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.(*WSClient).wsReader()
2022-10-21T08:59:45.2224077Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/wsclient.go:210 +0x651
2022-10-21T08:59:45.2224416Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.NewWS.func2()
2022-10-21T08:59:45.2224892Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/wsclient.go:149 +0x39
2022-10-21T08:59:45.2224901Z
2022-10-21T08:59:45.2225049Z Goroutine 371 (running) created at:
2022-10-21T08:59:45.2225182Z   testing.(*T).Run()
2022-10-21T08:59:45.2225548Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x724
2022-10-21T08:59:45.2225911Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.TestWSClientEvents()
2022-10-21T08:59:45.2226408Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/wsclient_test.go:167 +0x404
2022-10-21T08:59:45.2226539Z   testing.tRunner()
2022-10-21T08:59:45.2226900Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1439 +0x213
2022-10-21T08:59:45.2227042Z   testing.(*T).Run.func1()
2022-10-21T08:59:45.2227398Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x47
2022-10-21T08:59:45.2227406Z
2022-10-21T08:59:45.2227552Z Goroutine 37 (finished) created at:
2022-10-21T08:59:45.2227851Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.NewWS()
2022-10-21T08:59:45.2228327Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/wsclient.go:149 +0x6fb
2022-10-21T08:59:45.2228843Z   github.com/nspcc-dev/neo-go/pkg/rpcclient.TestWSClientEvents.func2()
2022-10-21T08:59:45.2229434Z       /home/runner/work/neo-go/neo-go/pkg/rpcclient/wsclient_test.go:168 +0x131
2022-10-21T08:59:45.2229569Z   testing.tRunner()
2022-10-21T08:59:45.2229930Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1439 +0x213
2022-10-21T08:59:45.2230069Z   testing.(*T).Run.func1()
2022-10-21T08:59:45.2230424Z       /opt/hostedtoolcache/go/1.18.7/x64/src/testing/testing.go:1486 +0x47
2022-10-21T08:59:45.2230526Z ==================
2022-10-21T08:59:45.2230703Z     wsclient_test.go:186:
2022-10-21T08:59:45.2230988Z         	Error Trace:	wsclient_test.go:186
2022-10-21T08:59:45.2231209Z         	Error:      	Should be true
2022-10-21T08:59:45.2231536Z         	Test:       	TestWSClientEvents/default_ntf_channel
2022-10-21T08:59:45.2231812Z     testing.go:1312: race detected during execution of test
```
2022-10-24 06:09:36 +03:00
Anna Shaleva
d2a9e9120d rpc: extend Waiter interface to wait for several txs with context 2022-10-24 06:09:36 +03:00
Anna Shaleva
6b216050f3 rpc: add compat tests for RPC* interfaces and Client implementations 2022-10-24 06:09:36 +03:00
Anna Shaleva
00d44235c1 rpc: add tests for RPC waiters 2022-10-24 06:09:36 +03:00
Anna Shaleva
388112dcaa rpc: mark old WSClient's SubscribeFor* methods as deprecated 2022-10-24 06:09:36 +03:00
Anna Shaleva
5b81cb065f rpc: refactor waiter-related actor code 2022-10-24 06:09:36 +03:00
Anna Shaleva
8e84bb51d5 rpc: add "till" filter to WS block events 2022-10-24 06:09:36 +03:00
Anna Shaleva
345d48d051 rpc: improve WS-based transaction awaiting
Subscribe only for required aers.
2022-10-24 06:09:36 +03:00
Anna Shaleva
d7c1f3eac7 rpc: add "container" filter to WS execution notifications 2022-10-24 06:09:36 +03:00
Anna Shaleva
71069b0ed0 rpc: improve WS-enabled transaction awaiting
Fetch blocks since VUB+1, if block received and we haven't returned the
result yet, then transaction wasn't accepted at all.
2022-10-24 06:09:36 +03:00
Anna Shaleva
673a495527 rpc: add "since" filter to WS block events 2022-10-24 06:09:36 +03:00
Anna Shaleva
10a0716217 rpc: implement transaction awaiting functionality
Close #2704.
2022-10-24 06:09:36 +03:00
Anna Shaleva
6d38e75149 rpc: support multiple WSClient notification receivers 2022-10-24 06:09:36 +03:00
Anna Shaleva
4ce6bc6a66 rpc: adjust comment to Notification value cast
And explicitly specify field names on Notification creation.
2022-10-24 06:09:36 +03:00
Roman Khimov
317dd42513 *: use uint*Size and SignatureLen constants where appropriate 2022-10-05 10:45:52 +03:00
Roman Khimov
d40eb79975 rpcclient: simplify historic API
util.Uint256 is util.Uint256 and it's same RPC behind the scenes, so we can
make it a bit easier to digest. See #2545 also.
2022-09-09 13:41:45 +03:00
Roman Khimov
541d4b49e1 context: define a constant for transaction context type 2022-09-08 14:33:04 +03:00
Roman Khimov
6be9367f03 rpcclient/notary: add OnNEP17PaymentData and an example
Update documentation as well to mention it and not mention outdated APIs. We
can't link them yet, this will be done after the release.
2022-09-08 14:33:04 +03:00
Roman Khimov
3c02177d3c rpcclient: improve comments for some methods 2022-09-08 14:33:04 +03:00
Roman Khimov
3e8e6857e5 rpcclient; deprecate more methods
They make little sense now.
2022-09-08 14:33:04 +03:00
Roman Khimov
c4ddf80742 rpcclient: correct Init requirement in documentation 2022-09-08 14:33:04 +03:00
Roman Khimov
ee55e95c28 rpcclient: add examples for nep11/nep17/neo
GAS doesn't need any, so just mention nep17 package there.
2022-09-08 14:33:04 +03:00
Roman Khimov
a1c9871d95 nns: it's NEP-11, so make NEP-11 methods available too 2022-09-08 14:33:04 +03:00
Roman Khimov
186e5c19b6 rpcclient: update documentation, mention subpackages
Drop TODOs (we have relevant GitHub issues), drop verbosity comment (we have
*Verbose APIs for that).
2022-09-08 14:33:04 +03:00
Roman Khimov
cb1a1f8532 actor: extend documentation, add example 2022-09-08 14:33:04 +03:00
Roman Khimov
e1fe76137e rpcclient: use separate reader/writer structs in nep11 and nep17
Which greatly simplifies reuse of these packages (and they're expected to be
reused since real tokens implement standards and also add something of their
own) and allows to avoid effects like

  doc_test.go:68:28: ambiguous selector neoContract.BalanceOf

when neo.Contract is used. Avoids duplication in NEP-11 implementation as
well.
2022-09-08 14:33:03 +03:00
Roman Khimov
00a9376311 invoker: update documentation, add example 2022-09-08 14:33:03 +03:00
Roman Khimov
aca8ce0d28 unwrap: provide ErrNoSessionID, add some explanations 2022-09-07 22:40:25 +03:00
Roman Khimov
c703ac6805 golangci: enable contextcheck linter, fix WSClient
pkg/rpcclient/wsclient.go:93:30  contextcheck  Function `Dial` should pass the context parameter
2022-09-02 18:35:54 +03:00
Roman Khimov
3c009271f8 golangci: enable bodyclose checker and fix related code
It has found an issue in the oracle code, so I think it's worth doing.
2022-09-02 18:35:54 +03:00
Roman Khimov
e164625a7f wallet: provide (*Account).SignHashable API
Make PrivateKey() less used and less useful.
2022-09-02 14:44:01 +03:00
Roman Khimov
e569edc841 wallet: add ScriptHash() to Account
It allows to simplify a lot of code and avoid getting a PrivateKey in some
cases.
2022-09-02 14:43:34 +03:00
Roman Khimov
314cd3341b
Merge pull request #2667 from nspcc-dev/rpc-nep-token-info
Drop NEPXXTokenInfo from the RPC client
2022-08-30 14:41:30 +03:00
Roman Khimov
673c8954cc
Merge pull request #2665 from nspcc-dev/notary-rpcclient
Notary RPC client
2022-08-30 12:43:13 +03:00
Roman Khimov
07f3023e84 rpcclient: add notary.Actor for seamless notary experience 2022-08-30 11:47:56 +03:00
Roman Khimov
ed6ed61712 neptoken: add Info to replace old NEPXXTokenInfo methods
I'm still not sure it's good to have this exposed from neptoken at all, but
let's try it this way.
2022-08-29 22:52:27 +03:00
Roman Khimov
a95984febf actor: allow providing default attributes/hooks to be used
Which expands Actor use cases greatly.
2022-08-29 15:08:37 +03:00
Roman Khimov
a3f32bf306 neptoken: move BalanceOf implementation to Base from nep11/nep17
It's the same, even though standards define parameter name in a bit different
way.
2022-08-26 21:52:19 +03:00
Roman Khimov
0d9158bd79 rpcclient: add enough of NNS into nns to deprecate NNS methods 2022-08-26 19:45:37 +03:00
Roman Khimov
2f8896f7a1 rpcclient: add notary subpackage with the notary contract wrapper 2022-08-26 18:21:58 +03:00
Roman Khimov
a2c4a7f611 rpcsrv: adjust for paid attritbutes in calculatenetworkfee
calculatenetworkfee MUST calculate complete proper network fee, if we have
some extensions enabled and some attributes should be paid for that they're a
part of the equation too.
2022-08-23 15:34:18 +03:00
Roman Khimov
f3d83c90b1 rpcsrv: allow invalid contract signatures in calculatenetworkfee
See #2805, it allows to cover more cases like Notary contract that can use
CalculateNetworkFee now instead of AddNetworkFee RPC client API.
2022-08-22 14:55:45 +03:00
Roman Khimov
b2524a3ba9 actor: add Sender helper method 2022-08-19 21:52:43 +03:00
Roman Khimov
c034f94a94 nep17: provide out of the box multitransfer capability
It can't replicate the old multitransfer methods in ability to transfer
multiple tokens, but it at the same time can do multiple senders.
2022-08-19 21:52:43 +03:00
Roman Khimov
194933a5cc rpcclient: provide nep11 package for NEP-11 tokens
Unfortunately Go doesn't allow to easily reuse readers in full packages, still
we can have this wrapper with a little overhead (the alternative is to move
specific methods into types of their own, but I'm not sure how it's going to
be accepted user-side).
2022-08-19 10:37:22 +03:00
Roman Khimov
d0702c2cf9 unwrap: provide ArrayOfUint160
It's a popular type as well.
2022-08-19 10:36:44 +03:00
Roman Khimov
f011b3c3dd rpcclient: introduce NEO wrapper
Notice that int64 types are used for gas per block or registration price
because the price has to fit into the system fee limitation and gas per block
value can't be more than 10 GAS. We use int64 for votes as well in other types
since NEO is limited to 100M.
2022-08-17 22:03:09 +03:00
Roman Khimov
79051f21c1 invoker: expand the interface with iterator wrappers
We need them for iterator-based interfaces. Invoker hides the difference
between different (session/expanded) iterators here.
2022-08-17 16:38:03 +03:00
Roman Khimov
689331b960 unwrap: perform consistency check in SessionIterator
C# servers with SessionEnabled=false will return iterator IDs and no session
IDs which can be reported as an error immediately because the iterator can't
be traversed.
2022-08-17 15:08:24 +03:00
Roman Khimov
37619743ad unwrap: add ArrayOfPublicKeys()
This type of result is also popular in the NEO contract.
2022-08-17 12:45:46 +03:00
Roman Khimov
0dbe8b6ce2 rpcclient: add oracle package for OracleContract 2022-08-17 11:42:20 +03:00
Roman Khimov
5c8f3a99dc rpcclient: add management wrapper for ContractManagement 2022-08-17 11:42:20 +03:00
Roman Khimov
5d5455312a rpcclient: add policy package for the PolicyContract contract
And test it with the RPC server.

Notice that getters still return int64 instead of *big.Int, that's because
these values are very limited and technically could even fit into an int (but
that seems to be too dangerous to use for long-term compatibility).
2022-08-16 12:43:25 +03:00
Roman Khimov
ee72b2fa29 rpcclient: add gas package for the GAS contract
Test it with the RPC server.
2022-08-16 12:43:25 +03:00
Roman Khimov
ee84a4ab32 rpcclient: add rolemgmt pkg for RoleManagement contract
And test it with RPC server.
2022-08-16 12:43:25 +03:00
Roman Khimov
c967005216 rpcclient: add deprecation notices
And fix test code using old APIs to pass linter checks.
2022-08-12 18:21:02 +03:00
Roman Khimov
be74cc6b55 cli: use nep17 wrapper to implement commands 2022-08-12 18:21:02 +03:00
Roman Khimov
309358c85b rpcclient: add new NEP-17 wrapper 2022-08-12 18:21:02 +03:00
Roman Khimov
f155a7f161 rpcclient: move result processing code into unwrap package
Which will be reused by upper-layer packages. It can be extended with more
types in future.
2022-08-09 17:38:47 +03:00
Roman Khimov
593fa4cac8
Merge pull request #2632 from nspcc-dev/rpcclient-actor
RPC client Actor interface
2022-08-09 17:21:24 +03:00
Anna Shaleva
916f2293b8 *: apply go 1.19 formatter heuristics
And make manual corrections where needed. See the "Common mistakes
and pitfalls" section of https://tip.golang.org/doc/comment.
2022-08-09 15:37:52 +03:00
Roman Khimov
ff72ed5715 actor: take ValidatorsHistory into account for CalculateValidUntilBlock
Which makes permanent result.Version caching safe for all cases.
2022-08-09 15:36:40 +03:00
Roman Khimov
afef8b85d9 rpcclient: add deprecation warnings 2022-08-08 09:51:51 +03:00
Roman Khimov
c0705e45c9 rpcclient: add actor package
Somewhat similar to invoker, but changing the state (or just creating a
transaction). Transaction creation could've been put into a structure of its
own, but it seems to be less convenient to use this way.
2022-08-07 22:33:56 +03:00
Roman Khimov
31c9ae6339 rpcclient: add CallAndExpandIterator to Invoker
And deprecate Client.InvokeAndPackIteratorResults.
2022-08-01 21:31:23 +03:00
Roman Khimov
b52282c3c7 rpcclient: use Invoker internally for external APIs
It's not a big improvement, but it allows to test Invoker better.
2022-08-01 21:31:23 +03:00
Roman Khimov
fee7e2f223 rpcclient: add invoker package and structure 2022-08-01 21:31:23 +03:00
Roman Khimov
a8a2f2ed5a smartcontract: make CreateCallAndUnwrapIteratorScript accept Go types
Parameter is for the RPC client, all other CreateXXXScript functions deal with
regular types.
2022-08-01 21:31:23 +03:00
Roman Khimov
3c5a720e3a smartcontract: drop Params type and TryParse methods
They were first introduced in a058598ecc and
then carefully moved in 648e0bb242, but it looks
like they were never used by any external code. This code can be useful on the
server, but the server has its own params package to deal with
parameters. Clients usually create Parameters and then get results as
stackitem.Items, so they don't use this code either. So there is zero point in
keeping it.
2022-08-01 21:31:23 +03:00
Roman Khimov
32ebb4a90d smartcontract: add Builder, method invocation helpers and doc
Move the last remaining script-related things out of the rpcclient.
2022-07-25 22:49:47 +03:00
Roman Khimov
1b6f4051d8 smartcontract: move CreateCallAndUnwrapIteratorScript there
RPC client shouldn't build scripts and this function can be useful as a
reusable building block.
2022-07-25 15:46:20 +03:00
Roman Khimov
b3c25b5a1f neorpc/result: move NotaryRequestEvent to this package
Not worth a package of its own.
2022-07-25 11:58:13 +03:00
Roman Khimov
4acd1688a1 subscriptions: move NotificationEvent to state
1. It's not good for pkg/core to import anything from pkg/neorpc.
2. The type is closely tied to the state package, even though it's not stored
   in the DB
2022-07-25 11:58:13 +03:00
Roman Khimov
1e0750e3cd rpc: merge response and request under pkg/neorpc
Move result there also.
2022-07-25 11:57:53 +03:00
Roman Khimov
8c668765d2 rpc/client: move to pkg/rpcclient
Better package name, closer to user.
2022-07-21 22:39:53 +03:00