Skip to content

Commit 3258dcf

Browse files
friedgerzone117x
authored andcommitted
fix(client): add readOnlyFunctionArgs
1 parent 2afc27c commit 3258dcf

File tree

6 files changed

+142
-47
lines changed

6 files changed

+142
-47
lines changed

client/src/generated/apis/SmartContractsApi.ts

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import {
2121
ContractSourceResponse,
2222
ContractSourceResponseFromJSON,
2323
ContractSourceResponseToJSON,
24+
ReadOnlyFunctionArgs,
25+
ReadOnlyFunctionArgsFromJSON,
26+
ReadOnlyFunctionArgsToJSON,
2427
ReadOnlyFunctionSuccessResponse,
2528
ReadOnlyFunctionSuccessResponseFromJSON,
2629
ReadOnlyFunctionSuccessResponseToJSON,
@@ -30,6 +33,7 @@ export interface CallReadOnlyFunctionRequest {
3033
stacksAddress: string;
3134
contractName: string;
3235
functionName: string;
36+
readOnlyFunctionArgs: ReadOnlyFunctionArgs;
3337
}
3438

3539
export interface GetContractByIdRequest {
@@ -81,15 +85,22 @@ export class SmartContractsApi extends runtime.BaseAPI {
8185
throw new runtime.RequiredError('functionName','Required parameter requestParameters.functionName was null or undefined when calling callReadOnlyFunction.');
8286
}
8387

88+
if (requestParameters.readOnlyFunctionArgs === null || requestParameters.readOnlyFunctionArgs === undefined) {
89+
throw new runtime.RequiredError('readOnlyFunctionArgs','Required parameter requestParameters.readOnlyFunctionArgs was null or undefined when calling callReadOnlyFunction.');
90+
}
91+
8492
const queryParameters: runtime.HTTPQuery = {};
8593

8694
const headerParameters: runtime.HTTPHeaders = {};
8795

96+
headerParameters['Content-Type'] = 'application/json';
97+
8898
const response = await this.request({
8999
path: `/v2/contracts/call-read/{stacks_address}/{contract_name}/{function_name}`.replace(`{${"stacks_address"}}`, encodeURIComponent(String(requestParameters.stacksAddress))).replace(`{${"contract_name"}}`, encodeURIComponent(String(requestParameters.contractName))).replace(`{${"function_name"}}`, encodeURIComponent(String(requestParameters.functionName))),
90100
method: 'POST',
91101
headers: headerParameters,
92102
query: queryParameters,
103+
body: ReadOnlyFunctionArgsToJSON(requestParameters.readOnlyFunctionArgs),
93104
});
94105

95106
return new runtime.JSONApiResponse(response, (jsonValue) => ReadOnlyFunctionSuccessResponseFromJSON(jsonValue));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
/**
4+
* Stacks 2.0 Blockchain API
5+
* This is the documentation for the Stacks 2.0 Blockchain API. It is comprised of two parts; the Stacks Blockchain API and the Stacks Core API. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/614feab5c108d292bffa#?env%5BStacks%20Blockchain%20API%5D=W3sia2V5Ijoic3R4X2FkZHJlc3MiLCJ2YWx1ZSI6IlNUMlRKUkhESE1ZQlE0MTdIRkIwQkRYNDMwVFFBNVBYUlg2NDk1RzFWIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJibG9ja19pZCIsInZhbHVlIjoiMHgiLCJlbmFibGVkIjp0cnVlfSx7ImtleSI6Im9mZnNldCIsInZhbHVlIjoiMCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoibGltaXRfdHgiLCJ2YWx1ZSI6IjIwMCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoibGltaXRfYmxvY2siLCJ2YWx1ZSI6IjMwIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJ0eF9pZCIsInZhbHVlIjoiMHg1NDA5MGMxNmE3MDJiNzUzYjQzMTE0ZTg4NGJjMTlhODBhNzk2MzhmZDQ0OWE0MGY4MDY4Y2RmMDAzY2RlNmUwIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJjb250cmFjdF9pZCIsInZhbHVlIjoiU1RKVFhFSlBKUFBWRE5BOUIwNTJOU1JSQkdRQ0ZOS1ZTMTc4VkdIMS5oZWxsb193b3JsZFxuIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJidGNfYWRkcmVzcyIsInZhbHVlIjoiYWJjIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJjb250cmFjdF9hZGRyZXNzIiwidmFsdWUiOiJTVEpUWEVKUEpQUFZETkE5QjA1Mk5TUlJCR1FDRk5LVlMxNzhWR0gxIiwiZW5hYmxlZCI6dHJ1ZX0seyJrZXkiOiJjb250cmFjdF9uYW1lIiwidmFsdWUiOiJoZWxsb193b3JsZCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoiY29udHJhY3RfbWFwIiwidmFsdWUiOiJzdG9yZSIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoiY29udHJhY3RfbWV0aG9kIiwidmFsdWUiOiJnZXQtdmFsdWUiLCJlbmFibGVkIjp0cnVlfV0=) ## Design ### Stacks Core API vs Stacks Blockchain API The blockchain\'s Rust implementation exposes a JSON RPC endpoint (\"Stacks Core API\"), which can be used to interface with the blockchain. It can be used directly. [See the documentation for the `stacks-blockchain` in its Github repository](https://github.com/blockstack/stacks-blockchain/) All `/v2/` routes a proxied to a Blockstack PBC-hosted Stacks Node. For a trustless architecture, you should make these requests to a self-hosted node. All `/extended/` routes are provided by the Stacks 2.0 Blockchain API directly. They extend the Stacks Core API capabilities to make it easier to integrate with. ### Pagination To make API responses more compact, lists returned by the API are paginated. For lists, the response body includes: - `limit`: the number of list items return per response - `offset`: the number of elements to skip (starting from `0`) - `total`: the number of all available list items - `results`: the array of list items (length of array equals the set limit) Using the `limit` and `offset` properties, you can paginate through the entire list by increasing the offset by the limit until you reach the total. ## Client Library A generated JS Client is available for consumption of this API. The client enables typesafe REST and WebSocket communication. Please review the [client documentation](https://blockstack.github.io/stacks-blockchain-api/client/index.html) for more details.
6+
*
7+
* The version of the OpenAPI document: 1.0.0
8+
*
9+
*
10+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
* https://openapi-generator.tech
12+
* Do not edit the class manually.
13+
*/
14+
15+
import { exists, mapValues } from '../runtime';
16+
/**
17+
* Describes representation of a Type-0 Stacks 2.0 transaction. https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md#type-0-transferring-an-asset
18+
* @export
19+
* @interface ReadOnlyFunctionArgs
20+
*/
21+
export interface ReadOnlyFunctionArgs {
22+
/**
23+
* The simulated tx-sender
24+
* @type {string}
25+
* @memberof ReadOnlyFunctionArgs
26+
*/
27+
sender: string;
28+
/**
29+
* An array of hex serialized Clarity values
30+
* @type {Array<string>}
31+
* @memberof ReadOnlyFunctionArgs
32+
*/
33+
arguments: Array<string>;
34+
}
35+
36+
export function ReadOnlyFunctionArgsFromJSON(json: any): ReadOnlyFunctionArgs {
37+
return ReadOnlyFunctionArgsFromJSONTyped(json, false);
38+
}
39+
40+
export function ReadOnlyFunctionArgsFromJSONTyped(json: any, ignoreDiscriminator: boolean): ReadOnlyFunctionArgs {
41+
if ((json === undefined) || (json === null)) {
42+
return json;
43+
}
44+
return {
45+
46+
'sender': json['sender'],
47+
'arguments': json['arguments'],
48+
};
49+
}
50+
51+
export function ReadOnlyFunctionArgsToJSON(value?: ReadOnlyFunctionArgs | null): any {
52+
if (value === undefined) {
53+
return undefined;
54+
}
55+
if (value === null) {
56+
return null;
57+
}
58+
return {
59+
60+
'sender': value.sender,
61+
'arguments': value.arguments,
62+
};
63+
}
64+
65+

client/src/generated/models/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export * from './MempoolTransactionListResponse';
1313
export * from './NetworkBlockTimeResponse';
1414
export * from './NetworkBlockTimesResponse';
1515
export * from './NetworkBlockTimesResponseMainnet';
16+
export * from './ReadOnlyFunctionArgs';
1617
export * from './ReadOnlyFunctionSuccessResponse';
1718
export * from './RunFaucetResponse';
1819
export * from './TransactionResults';

client/test/test.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import fetch from 'cross-fetch';
2-
import { Configuration, BlocksApi } from '../src/index';
2+
import { Configuration, BlocksApi, SmartContractsApi } from '../src/index';
33

44
(async () => {
5-
6-
const apiConfig = new Configuration({
5+
const apiConfig = new Configuration({
76
fetchApi: fetch, // `fetch` lib must be specified in Node.js environments
8-
basePath: 'https://sidecar.staging.blockstack.xyz' // defaults to http://localhost:3999
7+
basePath: 'https://stacks-node-api-latest.argon.blockstack.xyz', // defaults to http://localhost:3999
98
});
109

1110
const blockApi = new BlocksApi(apiConfig);
@@ -14,4 +13,15 @@ import { Configuration, BlocksApi } from '../src/index';
1413
console.log(blocks.total);
1514
console.log(blocks.results);
1615

17-
})().catch(console.error)
16+
const smartContractsApi = new SmartContractsApi(apiConfig);
17+
const readOnly = await smartContractsApi.callReadOnlyFunction({
18+
stacksAddress: 'ST12EY99GS4YKP0CP2CFW6SEPWQ2CGVRWK5GHKDRV',
19+
contractName: 'flip-coin-jackpot',
20+
functionName: 'get-optional-winner-at',
21+
readOnlyFunctionArgs: {
22+
sender: 'ST12EY99GS4YKP0CP2CFW6SEPWQ2CGVRWK5GHKDRV',
23+
arguments: ['0x0100000000000000000000000000000001'],
24+
},
25+
});
26+
console.log(readOnly);
27+
})().catch(console.error);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "ReadOnlyFunctionArgs",
4+
"description": "Describes representation of a Type-0 Stacks 2.0 transaction. https://github.com/blockstack/stacks-blockchain/blob/master/sip/sip-005-blocks-and-transactions.md#type-0-transferring-an-asset",
5+
"type": "object",
6+
"required": ["sender", "arguments"],
7+
"properties": {
8+
"sender": {
9+
"type": "string",
10+
"description": "The simulated tx-sender"
11+
},
12+
"arguments": {
13+
"type": "array",
14+
"description": "An array of hex serialized Clarity values",
15+
"items": {
16+
"type": "string"
17+
}
18+
}
19+
}
20+
}

docs/openapi.yaml

+30-42
Original file line numberDiff line numberDiff line change
@@ -425,49 +425,37 @@ paths:
425425
$ref: ./api/contract/post-call-read-only-fn-success.example.json
426426
fail:
427427
$ref: ./api/contract/post-call-read-only-fn-fail.example.json
428-
parameters:
429-
- name: stacks_address
430-
in: path
431-
required: true
432-
description: Stacks address
433-
schema:
434-
type: string
435-
- name: contract_name
436-
in: path
437-
required: true
438-
description: Contract name
439-
schema:
440-
type: string
441-
- name: function_name
442-
in: path
443-
required: true
444-
description: Function name
445-
schema:
446-
type: string
447-
requestBody:
448-
description: map of arguments and the simulated tx-sender where sender is either a Contract identifier or a normal Stacks address, and arguments is an array of hex serialized Clarity values.
449-
required: true
450-
content:
451-
application/json:
428+
parameters:
429+
- name: stacks_address
430+
in: path
431+
required: true
432+
description: Stacks address
433+
schema:
434+
type: string
435+
- name: contract_name
436+
in: path
437+
required: true
438+
description: Contract name
452439
schema:
453-
type: object
454-
properties:
455-
sender:
456-
type: string
457-
description: the simulated tx-sender
458-
arguments:
459-
type: array
460-
description: an array of hex serialized Clarity values
461-
items:
462-
type: string
463-
requires:
464-
- sender
465-
- arguments
466-
example:
467-
sender: 'SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info'
468-
arguments:
469-
- '0x0011...'
470-
- '0x00231...'
440+
type: string
441+
- name: function_name
442+
in: path
443+
required: true
444+
description: Function name
445+
schema:
446+
type: string
447+
requestBody:
448+
description: map of arguments and the simulated tx-sender where sender is either a Contract identifier or a normal Stacks address, and arguments is an array of hex serialized Clarity values.
449+
required: true
450+
content:
451+
application/json:
452+
schema:
453+
$ref: './entities/contracts/read-only-function-args.schema.json'
454+
example:
455+
sender: 'SP31DA6FTSJX2WGTZ69SFY11BH51NZMB0ZW97B5P0.get-info'
456+
arguments:
457+
- '0x0011...'
458+
- '0x00231...'
471459

472460
/extended/v1/address/{principal}/balances:
473461
get:

0 commit comments

Comments
 (0)