Skip to content

Commit 5732e9b

Browse files
authored
Merge pull request #23 from icon-project/feat/rpc-client
feat(rpc_client): implement rpc client
2 parents faa4fa7 + 5aad4f2 commit 5732e9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+10253
-1
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ func main() {
137137
}
138138
```
139139

140+
## Stacks RPC Client
141+
142+
The `rpc_client` package is automatically generated from the [Stacks RPC OpenAPI specification](https://github.com/stacks-network/stacks-core/blob/master/docs/rpc/openapi.yaml). Some modifications are made after generation.
143+
140144
## Contributing
141145
Contributions are welcome! Please feel free to submit a Pull Request.
142146

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ require (
1616
github.com/FactomProject/btcutilecc v0.0.0-20130527213604-d3a63a5752ec // indirect
1717
github.com/davecgh/go-spew v1.1.1 // indirect
1818
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
19+
github.com/kr/pretty v0.3.1 // indirect
1920
github.com/pmezard/go-difflib v1.0.0 // indirect
21+
github.com/rogpeppe/go-internal v1.12.0 // indirect
2022
golang.org/x/net v0.27.0 // indirect
23+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
2124
gopkg.in/yaml.v3 v3.0.1 // indirect
2225
)

go.sum

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOF
88
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc=
99
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e h1:0XBUw73chJ1VYSsfvcPvVT7auykAJce9FpRr10L6Qhw=
1010
github.com/cmars/basen v0.0.0-20150613233007-fe3947df716e/go.mod h1:P13beTBKr5Q18lJe1rIoLUqjM+CB1zYrRg44ZqGuQSA=
11+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1112
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1213
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1314
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -18,8 +19,19 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeC
1819
github.com/go-resty/resty/v2 v2.14.0 h1:/rhkzsAqGQkozwfKS5aFAbb6TyKd3zyFRWcdRXLPCAU=
1920
github.com/go-resty/resty/v2 v2.14.0/go.mod h1:IW6mekUOsElt9C7oWr0XRt9BNSD6D5rr9mhk6NjmNHg=
2021
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
22+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
23+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
24+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
25+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
26+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
27+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
28+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
29+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
2130
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2231
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
32+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
33+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
34+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
2335
github.com/stretchr/testify v1.1.5-0.20170601210322-f6abca593680/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
2436
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
2537
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
@@ -99,8 +111,9 @@ golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
99111
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
100112
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
101113
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
102-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
103114
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
115+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
116+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
104117
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
105118
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
106119
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
# Use this file to prevent files from being overwritten by the generator.
5+
# The patterns follow closely to .gitignore or .dockerignore.
6+
7+
# As an example, the C# client generator defines ApiClient.cs.
8+
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9+
#ApiClient.cs
10+
11+
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
12+
#foo/*/qux
13+
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14+
15+
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16+
#foo/**/qux
17+
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18+
19+
# You can also negate patterns with an exclamation (!).
20+
# For example, you can ignore all files in a docs folder with the file extension .md:
21+
#docs/*.md
22+
# Then explicitly reverse the ignore rule for a single file:
23+
#!docs/README.md
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.gitignore
2+
.travis.yml
3+
README.md
4+
api/openapi.yaml
5+
api_accounts.go
6+
api_blocks.go
7+
api_fees.go
8+
api_info.go
9+
api_mining.go
10+
api_smart_contracts.go
11+
api_transactions.go
12+
client.go
13+
configuration.go
14+
docs/AccountsAPI.md
15+
docs/BlocksAPI.md
16+
docs/FeesAPI.md
17+
docs/GetAccountDataschema.md
18+
docs/GetContractDataMapEntryschema.md
19+
docs/GetContractInterfaceschema.md
20+
docs/GetContractSourceschema.md
21+
docs/GetInfoschema.md
22+
docs/GetPoxschema.md
23+
docs/GetPoxschemaContractVersionsInner.md
24+
docs/GetPoxschemaCurrentCycle.md
25+
docs/GetPoxschemaNextCycle.md
26+
docs/InfoAPI.md
27+
docs/MiningAPI.md
28+
docs/PostCallReadOnlyFnschema.md
29+
docs/PostCoreNodeTransactionsErrorschema.md
30+
docs/PostFeeTransactionResponseschema.md
31+
docs/PostFeeTransactionResponseschemaEstimatedCost.md
32+
docs/PostFeeTransactionResponseschemaEstimationsInner.md
33+
docs/PostFeeTransactionschema.md
34+
docs/ReadOnlyFunctionArgsschema.md
35+
docs/SmartContractsAPI.md
36+
docs/TransactionsAPI.md
37+
git_push.sh
38+
go.mod
39+
go.sum
40+
model_get_account_dataschema.go
41+
model_get_contract_data_map_entryschema.go
42+
model_get_contract_interfaceschema.go
43+
model_get_contract_sourceschema.go
44+
model_get_infoschema.go
45+
model_get_poxschema.go
46+
model_get_poxschema_contract_versions_inner.go
47+
model_get_poxschema_current_cycle.go
48+
model_get_poxschema_next_cycle.go
49+
model_post_call_read_only_fnschema.go
50+
model_post_core_node_transactions_errorschema.go
51+
model_post_fee_transaction_responseschema.go
52+
model_post_fee_transaction_responseschema_estimated_cost.go
53+
model_post_fee_transaction_responseschema_estimations_inner.go
54+
model_post_fee_transactionschema.go
55+
model_read_only_function_argsschema.go
56+
response.go
57+
test/api_accounts_test.go
58+
test/api_blocks_test.go
59+
test/api_fees_test.go
60+
test/api_info_test.go
61+
test/api_mining_test.go
62+
test/api_smart_contracts_test.go
63+
test/api_transactions_test.go
64+
utils.go
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.8.0

pkg/rpc_client/README.md

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Go API client for rpc_client
2+
3+
This is the documentation for the `stacks-node` RPC interface.
4+
5+
6+
## Overview
7+
This API client was generated by the [OpenAPI Generator](https://openapi-generator.tech) project. By using the [OpenAPI-spec](https://www.openapis.org/) from a remote server, you can easily generate an API client.
8+
9+
- API version: 1.0.0
10+
- Package version: 1.0.0
11+
- Generator version: 7.8.0
12+
- Build package: org.openapitools.codegen.languages.GoClientCodegen
13+
14+
## Installation
15+
16+
Install the following dependencies:
17+
18+
```sh
19+
go get github.com/stretchr/testify/assert
20+
go get golang.org/x/net/context
21+
```
22+
23+
Put the package under your project folder and add the following in import:
24+
25+
```go
26+
import rpc_client "github.com/GIT_USER_ID/GIT_REPO_ID"
27+
```
28+
29+
To use a proxy, set the environment variable `HTTP_PROXY`:
30+
31+
```go
32+
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")
33+
```
34+
35+
## Configuration of Server URL
36+
37+
Default configuration comes with `Servers` field that contains server objects as defined in the OpenAPI specification.
38+
39+
### Select Server Configuration
40+
41+
For using other server than the one defined on index 0 set context value `rpc_client.ContextServerIndex` of type `int`.
42+
43+
```go
44+
ctx := context.WithValue(context.Background(), rpc_client.ContextServerIndex, 1)
45+
```
46+
47+
### Templated Server URL
48+
49+
Templated server URL is formatted using default variables from configuration or from context value `rpc_client.ContextServerVariables` of type `map[string]string`.
50+
51+
```go
52+
ctx := context.WithValue(context.Background(), rpc_client.ContextServerVariables, map[string]string{
53+
"basePath": "v2",
54+
})
55+
```
56+
57+
Note, enum values are always validated and all unused variables are silently ignored.
58+
59+
### URLs Configuration per Operation
60+
61+
Each operation can use different server URL defined using `OperationServers` map in the `Configuration`.
62+
An operation is uniquely identified by `"{classname}Service.{nickname}"` string.
63+
Similar rules for overriding default operation server index and variables applies by using `rpc_client.ContextOperationServerIndices` and `rpc_client.ContextOperationServerVariables` context maps.
64+
65+
```go
66+
ctx := context.WithValue(context.Background(), rpc_client.ContextOperationServerIndices, map[string]int{
67+
"{classname}Service.{nickname}": 2,
68+
})
69+
ctx = context.WithValue(context.Background(), rpc_client.ContextOperationServerVariables, map[string]map[string]string{
70+
"{classname}Service.{nickname}": {
71+
"port": "8443",
72+
},
73+
})
74+
```
75+
76+
## Documentation for API Endpoints
77+
78+
All URIs are relative to *http://localhost:20443*
79+
80+
Class | Method | HTTP request | Description
81+
------------ | ------------- | ------------- | -------------
82+
*AccountsAPI* | [**GetAccountInfo**](docs/AccountsAPI.md#getaccountinfo) | **Get** /v2/accounts/{principal} | Get account info
83+
*BlocksAPI* | [**GetBlockV3**](docs/BlocksAPI.md#getblockv3) | **Get** /v3/blocks/{block_id} | Fetch a Nakamoto block
84+
*BlocksAPI* | [**GetTenureInfo**](docs/BlocksAPI.md#gettenureinfo) | **Get** /v3/tenures/info | Fetch metadata about the ongoing Nakamoto tenure
85+
*BlocksAPI* | [**GetTenures**](docs/BlocksAPI.md#gettenures) | **Get** /v3/tenures/{block_id} | Fetch a sequence of Nakamoto blocks in a tenure
86+
*FeesAPI* | [**GetFeeTransfer**](docs/FeesAPI.md#getfeetransfer) | **Get** /v2/fees/transfer | Get estimated fee
87+
*FeesAPI* | [**PostFeeTransaction**](docs/FeesAPI.md#postfeetransaction) | **Post** /v2/fees/transaction | Get approximate fees for the given transaction
88+
*InfoAPI* | [**GetBurnOps**](docs/InfoAPI.md#getburnops) | **Get** /v2/burn_ops/{burn_height}/{op_type} | Get burn operations
89+
*InfoAPI* | [**GetCoreApiInfo**](docs/InfoAPI.md#getcoreapiinfo) | **Get** /v2/info | Get Core API info
90+
*InfoAPI* | [**GetPoxInfo**](docs/InfoAPI.md#getpoxinfo) | **Get** /v2/pox | Get PoX details
91+
*MiningAPI* | [**GetStackerSet**](docs/MiningAPI.md#getstackerset) | **Get** /v2/stacker_set/{cycle_number} | Fetch the stacker and signer set information for a given cycle.
92+
*MiningAPI* | [**PostBlockProposal**](docs/MiningAPI.md#postblockproposal) | **Post** /v2/block_proposal | Validate a proposed Stacks block
93+
*SmartContractsAPI* | [**CallReadOnlyFunction**](docs/SmartContractsAPI.md#callreadonlyfunction) | **Post** /v2/contracts/call-read/{contract_address}/{contract_name}/{function_name} | Call read-only function
94+
*SmartContractsAPI* | [**GetConstantVal**](docs/SmartContractsAPI.md#getconstantval) | **Post** /v2/constant_val/{contract_address}/{contract_name}/{constant_name} | Get the value of a constant inside a contract
95+
*SmartContractsAPI* | [**GetContractDataMapEntry**](docs/SmartContractsAPI.md#getcontractdatamapentry) | **Post** /v2/map_entry/{contract_address}/{contract_name}/{map_name} | Get specific data-map inside a contract
96+
*SmartContractsAPI* | [**GetContractInterface**](docs/SmartContractsAPI.md#getcontractinterface) | **Get** /v2/contracts/interface/{contract_address}/{contract_name} | Get contract interface
97+
*SmartContractsAPI* | [**GetContractSource**](docs/SmartContractsAPI.md#getcontractsource) | **Get** /v2/contracts/source/{contract_address}/{contract_name} | Get contract source
98+
*SmartContractsAPI* | [**GetIsTraitImplemented**](docs/SmartContractsAPI.md#getistraitimplemented) | **Get** /v2/traits/{contract_address}/{contract_name}/{trait_contract_address}/{trait_contract_name}/{trait_name} | Get trait implementation details
99+
*TransactionsAPI* | [**PostCoreNodeTransactions**](docs/TransactionsAPI.md#postcorenodetransactions) | **Post** /v2/transactions | Broadcast raw transaction
100+
101+
102+
## Documentation For Models
103+
104+
- [GetAccountDataschema](docs/GetAccountDataschema.md)
105+
- [GetContractDataMapEntryschema](docs/GetContractDataMapEntryschema.md)
106+
- [GetContractInterfaceschema](docs/GetContractInterfaceschema.md)
107+
- [GetContractSourceschema](docs/GetContractSourceschema.md)
108+
- [GetInfoschema](docs/GetInfoschema.md)
109+
- [GetPoxschema](docs/GetPoxschema.md)
110+
- [GetPoxschemaContractVersionsInner](docs/GetPoxschemaContractVersionsInner.md)
111+
- [GetPoxschemaCurrentCycle](docs/GetPoxschemaCurrentCycle.md)
112+
- [GetPoxschemaNextCycle](docs/GetPoxschemaNextCycle.md)
113+
- [PostCallReadOnlyFnschema](docs/PostCallReadOnlyFnschema.md)
114+
- [PostCoreNodeTransactionsErrorschema](docs/PostCoreNodeTransactionsErrorschema.md)
115+
- [PostFeeTransactionResponseschema](docs/PostFeeTransactionResponseschema.md)
116+
- [PostFeeTransactionResponseschemaEstimatedCost](docs/PostFeeTransactionResponseschemaEstimatedCost.md)
117+
- [PostFeeTransactionResponseschemaEstimationsInner](docs/PostFeeTransactionResponseschemaEstimationsInner.md)
118+
- [PostFeeTransactionschema](docs/PostFeeTransactionschema.md)
119+
- [ReadOnlyFunctionArgsschema](docs/ReadOnlyFunctionArgsschema.md)
120+
121+
122+
## Documentation For Authorization
123+
124+
Endpoints do not require authorization.
125+
126+
127+
## Documentation for Utility Methods
128+
129+
Due to the fact that model structure members are all pointers, this package contains
130+
a number of utility functions to easily obtain pointers to values of basic types.
131+
Each of these functions takes a value of the given basic type and returns a pointer to it:
132+
133+
* `PtrBool`
134+
* `PtrInt`
135+
* `PtrInt32`
136+
* `PtrInt64`
137+
* `PtrFloat`
138+
* `PtrFloat32`
139+
* `PtrFloat64`
140+
* `PtrString`
141+
* `PtrTime`
142+
143+
## Author
144+
145+
146+

0 commit comments

Comments
 (0)