1 unstable release
0.1.0 | Feb 28, 2023 |
---|
#25 in #prototype
70KB
1.5K
SLoC
REST API example application
This is a prototype of a Rust SDK providing functionality for interacting with the Newcoin network.
The expected api functionality is exampled via the main.rs
file.
//** This command will not yet work as rs_ncdao has not yet been uploaded to crates.io. **//
Install
cargo install nc_rsdk
Run the app
cargo run
Run the tests
cargo test
Get Table Rows/With Payload:
let gtr_response = get_table_rows().await;
let data_1 = gtr_response.text().await?;
let gtr_wp_response = get_proposal_by_id(&payload).await;
let data_2 = gtr_wp_response.unwrap_err();
let gtr_wp: Response = get_table_rows_with_payload(&payload).await.unwrap();
@newfound8ion/newcoin-sdk / Exports
@newfound8ion/newcoin-rs-api
Table of contents
Namespaces
Classes
Type Aliases
- NCApproveDaoProposal
- NCBuyRam
- NCChangeFile
- NCCreateCollection
- NCCreateDao
- NCCreateDaoProposal
- NCCreateDaoStakeProposal
- NCCreateDaoUserWhitelistProposal
- NCCreatePermission
- NCCreatePool
- NCCreateUser
- NCDaoProposalVote
- NCDaoWithdrawVoteDeposit
- NCExecuteDaoProposal
- NCGetAccInfo
- NCGetDaoProposals
- NCGetDaoWhiteList
- NCGetPoolInfo
- NCGetVotes
- NCKeyPair
- NCKeyValPair
- NCLinkPerm
- NCMintAsset
- NCMintFile
- NCMintLink
- NCMintProfile
- NCModifyAsset
- NCNameType
- NCPoolsInfo
- NCReturnInfo
- NCReturnTxs
- NCStakeMainDao
- NCStakePool
- NCTxBal
- NCTxNcoBal
- NCUnstakePool
Variables
Type Aliases
NCApproveDaoProposal
Ƭ NCApproveDaoProposal: Struct
Type declaration
Name | Type |
---|---|
approver |
String |
approver_prv_key |
String |
dao_id |
u32 |
dao_owner |
String |
proposal_author |
String |
proposal_id |
u32 |
Defined in
NCBuyRam
Ƭ NCBuyRam: Struct
Type declaration
Name | Type |
---|---|
payer |
String |
payer_prv_key |
String |
ram_amt |
u32 |
user |
String |
Defined in
NCChangeFile
Ƭ NCChangeFile: Struct
Type declaration
Name | Type |
---|---|
asset_id |
String |
editor |
String |
new_content |
String |
new_image |
String |
new_name |
String |
new_path |
String |
owner |
String |
payer |
String |
payer_prv_key |
String |
Defined in
NCCreateCollection
Ƭ NCCreateCollection: Struct
Type declaration
Name | Type |
---|---|
allow_notify |
bool |
burnable |
bool |
collection_name |
String |
max_supply |
u32 |
mkt_fee |
u32 |
schema_fields |
Vec<NCNameType> |
schema_name |
String |
template_fields |
Vec<NCNameType> |
template_name |
String |
user |
String |
user_prv_active_key |
String |
xferable |
bool |
Defined in
NCCreateDao
Ƭ NCCreateDao: Struct
Type declaration
Name | Type |
---|---|
author |
String |
author_prv_key |
String |
descr |
String |
token |
String |
Defined in
NCCreateDaoProposal
Ƭ NCCreateDaoProposal: Struct
Type declaration
Name | Type |
---|---|
dao_id |
String |
dao_owner |
String |
pass_rate |
u32 |
proposer |
String |
proposer_prv_key |
String |
summary |
String |
title |
String |
url |
String |
vote_end |
String |
vote_start |
String |
Defined in
NCCreateDaoStakeProposal
Ƭ NCCreateDaoStakeProposal: Struct
Type declaration
Name | Type |
---|---|
dao_id |
String |
dao_owner |
String |
pass_rate |
u32 |
proposer |
String |
proposer_prv_key |
String |
quantity |
(Struct ) { contract : String , quantity : String } |
quantity.contract |
String |
quantity.quantity |
String |
to |
String |
vote_end |
String |
vote_start |
String |
Defined in
NCCreateDaoUserWhitelistProposal
Ƭ NCCreateDaoUserWhitelistProposal: Struct
Type declaration
Name | Type |
---|---|
dao_id |
String |
dao_owner |
String |
pass_rate |
u32 |
proposer |
String |
proposer_prv_key |
String |
type |
String |
user |
String |
vote_end |
String |
vote_start |
String |
Defined in
NCCreatePermission
Ƭ NCCreatePermission: Struct
Type declaration
Name | Type |
---|---|
author |
String |
author_prv_active_key |
String |
perm_name |
String |
perm_pub_key |
String |
Defined in
NCCreatePool
Ƭ NCCreatePool: Struct
Type declaration
Name | Type |
---|---|
is_deflatable |
bool |
is_inflatable |
bool |
is_treasury |
bool |
owner |
String |
owner_prv_active_key |
String |
ticker |
String |
Defined in
NCCreateUser
Ƭ NCCreateUser: Struct
Type declaration
Name | Type |
---|---|
cpu_amount |
String |
net_amount |
String |
newUser |
String |
newacc_pub_active_key |
String |
newacc_pub_owner_key |
String |
payer |
String |
payer_prv_key |
String |
ram_amt |
u32 |
xfer |
bool |
Defined in
NCDaoProposalVote
Ƭ NCDaoProposalVote: Struct
Type declaration
Name | Type |
---|---|
dao_id |
String |
dao_owner |
String |
option |
String |
proposal_id |
String |
proposal_type |
String |
quantity |
String |
voter |
String |
voter_prv_key |
String |
Defined in
NCDaoWithdrawVoteDeposit
Ƭ NCDaoWithdrawVoteDeposit: Struct
Type declaration
Name | Type |
---|---|
vote_id |
String |
voter |
String |
voter_prv_key |
String |
Defined in
NCExecuteDaoProposal
Ƭ NCExecuteDaoProposal: Struct
Type declaration
Name | Type |
---|---|
dao_id |
u32 |
dao_owner |
String |
exec |
String |
exec_prv_key |
String |
proposal_author |
String |
proposal_id |
u32 |
Defined in
NCGetAccInfo
Ƭ NCGetAccInfo: Struct
Type declaration
Name | Type |
---|---|
contract |
String |
owner |
String |
token_name |
String |
Defined in
NCGetDaoProposals
Ƭ NCGetDaoProposals: Struct
Type declaration
Name | Type |
---|---|
dao_id |
String |
dao_owner |
String |
limit |
u32 |
lower_bound |
String |
proposal_author |
String |
proposal_id |
String |
reverse |
bool |
upper_bound |
String |
Defined in
NCGetDaoWhiteList
Ƭ NCGetDaoWhiteList: Struct
Type declaration
Name | Type |
---|---|
dao_id |
String |
dao_owner |
String |
limit |
String |
lower_bound |
String |
reverse |
bool |
upper_bound |
String |
Defined in
NCGetPoolInfo
Ƭ NCGetPoolInfo: Struct
Type declaration
Name | Type |
---|---|
code |
String |
owner |
String |
Defined in
NCGetVotes
Ƭ NCGetVotes: Struct
Type declaration
Name | Type |
---|---|
limit |
String |
lower_bound |
String |
reverse |
bool |
upper_bound |
String |
voter |
String |
Defined in
NCKeyPair
Ƭ NCKeyPair: Struct
Type declaration
Name | Type |
---|---|
prv_key |
String |
pub_key |
String |
Defined in
NCKeyValPair
Ƭ NCKeyValPair: Struct
Type declaration
Name | Type |
---|---|
key |
String |
value |
Vec<String> |
Defined in
NCLinkPerm
Ƭ NCLinkPerm: Struct
Type declaration
Name | Type |
---|---|
action_owner |
String |
action_to_link |
String |
author |
String |
author_prv_active_key |
String |
perm_to_link |
String |
Defined in
NCMintAsset
Ƭ NCMintAsset: Struct
Type declaration
Name | Type |
---|---|
col_name |
String |
creator |
String |
immutable_data |
Vec<NCKeyValPair> |
mutable_data |
Vec<NCKeyValPair> |
payer |
String |
payer_prv_key |
String |
sch_name |
String |
tmpl_id |
u32 |
user_prv_active_key |
String |
Defined in
NCMintFile
Ƭ NCMintFile: Struct
Type declaration
Name | Type |
---|---|
content |
String |
creator |
String |
image |
String |
name |
String |
path |
String |
payer |
String |
payer_prv_key |
String |
user_prv_active_key |
String |
Defined in
NCMintLink
Ƭ NCMintLink: Struct
Type declaration
Name | Type |
---|---|
col_name |
String |
creator |
String |
description |
String |
image |
String |
payer |
String |
payer_prv_key |
String |
subj_name |
String |
subj_type |
String |
Defined in
NCMintProfile
Ƭ NCMintProfile: Struct
Type declaration
Name | Type |
---|---|
apple |
String |
aspectRatio |
String |
authority |
String |
bio |
String |
blurHash |
String |
content |
String |
contentType |
String |
contentUrl |
String |
coverContentUrl |
String |
creator |
String |
discord |
String |
displayName |
String |
email |
String |
facebook |
String |
facebookId |
String |
firstName |
String |
fullName |
String |
instagram |
String |
lastName |
String |
medium |
String |
offer |
String |
payer |
String |
payer_prv_key |
String |
phone |
String |
pinterest |
String |
reddit |
String |
signal |
String |
signature |
String |
snapchat |
String |
soundcloud |
String |
source |
String |
spotify |
String |
status |
String |
telegram |
String |
tiktok |
String |
tumblr |
String |
twitter |
String |
user_prv_active_key |
String |
username |
String |
youtube |
String |
youtubeId |
String |
Defined in
NCModifyAsset
Ƭ NCModifyAsset: Struct
Type declaration
Name | Type |
---|---|
asset_id |
String |
editor |
String |
new_data |
Vec<NCKeyValPair> |
owner |
String |
payer |
String |
payer_prv_key |
String |
Defined in
NCNameType
Ƭ NCNameType: Struct
Type declaration
Name | Type |
---|---|
name |
String |
type |
String |
Defined in
NCPoolsInfo
Ƭ NCPoolsInfo: Struct
Type declaration
Name | Type |
---|---|
more |
bool |
next_key |
String |
rows |
Vec<NCPoolInfo> |
Defined in
NCReturnInfo
Ƭ NCReturnInfo: Struct
Type declaration
Name | Type |
---|---|
acc_balances |
Vec<String> |
Defined in
NCReturnTxs
Ƭ NCReturnTxs: Struct
Type declaration
Name | Type |
---|---|
TxID |
String |
TxID_WithdrawVoteDeposit |
String |
TxID_addToWhiteList |
String |
TxID_approveDaoProposal |
String |
TxID_changeFile |
String |
TxID_createAcc |
String |
TxID_createCol |
String |
TxID_createDao |
String |
TxID_createDaoProposal |
String |
TxID_createPerm |
String |
TxID_createPool |
String |
TxID_createSch |
String |
TxID_createTpl |
String |
TxID_executeDaoProposal |
String |
TxID_linkPerm |
String |
TxID_mintAsset |
String |
TxID_mintFile |
String |
TxID_mintNft |
String |
TxID_mintProfile |
String |
TxID_modifyAsset |
String |
TxID_removeFromWhiteList |
String |
TxID_stakeMainDAO |
String |
TxID_stakePool |
String |
TxID_txNcoBalance |
String |
TxID_unstakeMainDAO |
String |
TxID_unstakePool |
String |
TxID_voteDaoProposal |
String |
TxID_withdrawFromPool |
String |
asset_id |
String |
dao_id |
String |
pool_code |
String |
pool_id |
String |
proposal_id |
u32 |
template_id |
String |
tx |
TransactResult |
Defined in
NCStakeMainDao
Ƭ NCStakeMainDao: Struct
Type declaration
Name | Type |
---|---|
amt |
String |
payer |
String |
payer_prv_key |
String |
Defined in
NCStakePool
Ƭ NCStakePool: Struct
Type declaration
Name | Type |
---|---|
amt |
String |
owner |
String |
payer |
String |
payer_prv_key |
String |
Defined in
NCTxBal
Ƭ NCTxBal: Struct
Type declaration
Name | Type |
---|---|
amt |
String |
memo |
String |
payer |
String |
payer_prv_key |
String |
to |
String |
Defined in
NCTxNcoBal
Ƭ NCTxNcoBal: Struct
Type declaration
Name | Type |
---|---|
amt |
String |
memo |
String |
payer |
String |
payer_prv_key |
String |
to |
String |
Defined in
NCUnstakePool
Ƭ NCUnstakePool: Struct
Type declaration
Name | Type |
---|---|
amt |
String |
payer |
String |
payer_prv_key |
String |
Defined in
Variables
default_nft_schema
• Const
default_nft_schema: { name
: String
, nft_schema_type
: String
}
Defined in
devnet_services
• Const
devnet_services: NCInitServices
Defined in
devnet_urls
• Const
devnet_urls: NCInitUrls
Defined in
file_schema
• Const
file_schema: { name
: String
, file_schema_type
: String
}[]
Defined in
link_schema
• Const
link_schema: { name
: String
, link_schema_type
: String
}[]
Defined in
profile_schema
• Const
profile_schema: { name
: String
, profile_schema_type
: String
}[]
Defined in
//** As of yet, the text below has not been reworked for the application.** //
REST API
The REST API to the example app is described below.
Get list of Things
Request
GET /thing/
curl -i -H 'Accept: application/json' http://localhost:7000/thing/
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 2
[]
Get Dao Proposal by Id:
let url_val = NCInitUrlsDev::default().nodeos_url.clone();
let gtr_response: Response = get_table_rows().await;
let data = gtr_response.json().await;
Request
POST /thing/
curl -i -H 'Accept: application/json' -d 'name=Foo&status=new' http://localhost:7000/thing
Response
HTTP/1.1 201 Created
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/1
Content-Length: 36
{"id":1,"name":"Foo","status":"new"}
Get a specific Thing
Request
GET /thing/id
curl -i -H 'Accept: application/json' http://localhost:7000/thing/1
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 36
{"id":1,"name":"Foo","status":"new"}
Get a non-existent Thing
Request
GET /thing/id
curl -i -H 'Accept: application/json' http://localhost:7000/thing/9999
Response
HTTP/1.1 404 Not Found
Date: Thu, 24 Feb 2011 12:36:30 GMT
Status: 404 Not Found
Connection: close
Content-Type: application/json
Content-Length: 35
{"status":404,"reason":"Not found"}
Create another new Thing
Request
POST /thing/
curl -i -H 'Accept: application/json' -d 'name=Bar&junk=rubbish' http://localhost:7000/thing
Response
HTTP/1.1 201 Created
Date: Thu, 24 Feb 2011 12:36:31 GMT
Status: 201 Created
Connection: close
Content-Type: application/json
Location: /thing/2
Content-Length: 35
{"id":2,"name":"Bar","status":null}
Get list of Things again
Request
GET /thing/
curl -i -H 'Accept: application/json' http://localhost:7000/thing/
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:31 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 74
[{"id":1,"name":"Foo","status":"new"},{"id":2,"name":"Bar","status":null}]
Change a Thing's state
Request
PUT /thing/:id/status/changed
curl -i -H 'Accept: application/json' -X PUT http://localhost:7000/thing/1/status/changed
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:31 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 40
{"id":1,"name":"Foo","status":"changed"}
Get changed Thing
Request
GET /thing/id
curl -i -H 'Accept: application/json' http://localhost:7000/thing/1
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:31 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 40
{"id":1,"name":"Foo","status":"changed"}
Change a Thing
Request
PUT /thing/:id
curl -i -H 'Accept: application/json' -X PUT -d 'name=Foo&status=changed2' http://localhost:7000/thing/1
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:31 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 41
{"id":1,"name":"Foo","status":"changed2"}
Attempt to change a Thing using partial params
Request
PUT /thing/:id
curl -i -H 'Accept: application/json' -X PUT -d 'status=changed3' http://localhost:7000/thing/1
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:32 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 41
{"id":1,"name":"Foo","status":"changed3"}
Attempt to change a Thing using invalid params
Request
PUT /thing/:id
curl -i -H 'Accept: application/json' -X PUT -d 'id=99&status=changed4' http://localhost:7000/thing/1
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:32 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 41
{"id":1,"name":"Foo","status":"changed4"}
Change a Thing using the _method hack
Request
POST /thing/:id_method=POST
curl -i -H 'Accept: application/json' -X POST -d 'name=Baz&_method=PUT' http://localhost:7000/thing/1
Response
HTTP/1.1 200 OK
Date: Thu, 24 Feb 2011 12:36:32 GMT
Status: 200 OK
Connection: close
Content-Type: application/json
Content-Length: 41
{"id":1,"name":"Baz","status":"changed4"}
Change a Thing using the _method hack in the url
Request
POST /thing/:id_method=POST
curl -i -H 'Accept: application/json' -X POST -d 'name=Qux' http://localhost:7000/thing/1_method=PUT
Response
HTTP/1.1 404 Not Found
Date: Thu, 24 Feb 2011 12:36:32 GMT
Status: 404 Not Found
Connection: close
Content-Type: text/html;charset=utf-8
Content-Length: 35
{"status":404,"reason":"Not found"}
Delete a Thing
Request
DELETE /thing/id
curl -i -H 'Accept: application/json' -X DELETE http://localhost:7000/thing/1/
Response
HTTP/1.1 204 No Content
Date: Thu, 24 Feb 2011 12:36:32 GMT
Status: 204 No Content
Connection: close
Try to delete same Thing again
Request
DELETE /thing/id
curl -i -H 'Accept: application/json' -X DELETE http://localhost:7000/thing/1/
Response
HTTP/1.1 404 Not Found
Date: Thu, 24 Feb 2011 12:36:32 GMT
Status: 404 Not Found
Connection: close
Content-Type: application/json
Content-Length: 35
{"status":404,"reason":"Not found"}
Get deleted Thing
Request
GET /thing/1
curl -i -H 'Accept: application/json' http://localhost:7000/thing/1
Response
HTTP/1.1 404 Not Found
Date: Thu, 24 Feb 2011 12:36:33 GMT
Status: 404 Not Found
Connection: close
Content-Type: application/json
Content-Length: 35
{"status":404,"reason":"Not found"}
Delete a Thing using the _method hack
Request
DELETE /thing/id
curl -i -H 'Accept: application/json' -X POST -d'_method=DELETE' http://localhost:7000/thing/2/
Response
HTTP/1.1 204 No Content
Date: Thu, 24 Feb 2011 12:36:33 GMT
Status: 204 No Content
Connection: close
Dependencies
~8–20MB
~305K SLoC