-
Notifications
You must be signed in to change notification settings - Fork 13
/
contract.go
57 lines (47 loc) · 2.04 KB
/
contract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package client
import (
"context"
"github.com/eteu-technologies/near-api-go/pkg/client/block"
"github.com/eteu-technologies/near-api-go/pkg/jsonrpc"
"github.com/eteu-technologies/near-api-go/pkg/types"
)
// TODO: decode response
// https://docs.near.org/docs/develop/front-end/rpc#view-contract-state
func (c *Client) ContractViewState(ctx context.Context, accountID types.AccountID, prefixBase64 string, block block.BlockCharacteristic) (res jsonrpc.Response, err error) {
res, err = c.doRPC(ctx, nil, "query", block, map[string]interface{}{
"request_type": "view_state",
"account_id": accountID,
"prefix_base64": prefixBase64,
})
return
}
// TODO: decode response
// https://docs.near.org/docs/develop/front-end/rpc#view-contract-state-changes
func (c *Client) ContractViewStateChanges(ctx context.Context, accountIDs []types.AccountID, keyPrefixBase64 string, block block.BlockCharacteristic) (res jsonrpc.Response, err error) {
res, err = c.doRPC(ctx, nil, "EXPERIMENTAL_changes", block, map[string]interface{}{
"changes_type": "data_changes",
"account_ids": accountIDs,
"key_prefix_base64": keyPrefixBase64,
})
return
}
// TODO: decode response
// https://docs.near.org/docs/develop/front-end/rpc#view-contract-code-changes
func (c *Client) ContractViewCodeChanges(ctx context.Context, accountIDs []types.AccountID, block block.BlockCharacteristic) (res jsonrpc.Response, err error) {
res, err = c.doRPC(ctx, nil, "EXPERIMENTAL_changes", block, map[string]interface{}{
"changes_type": "contract_code_changes",
"account_ids": accountIDs,
})
return
}
// TODO: decode response
// https://docs.near.org/docs/develop/front-end/rpc#call-a-contract-function
func (c *Client) ContractViewCallFunction(ctx context.Context, accountID, methodName, argsBase64 string, block block.BlockCharacteristic) (res jsonrpc.Response, err error) {
res, err = c.doRPC(ctx, nil, "query", block, map[string]interface{}{
"request_type": "call_function",
"account_id": accountID,
"method_name": methodName,
"args_base64": argsBase64,
})
return
}