-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Re-exported near-abi-client (#303)
- Loading branch information
Yasir Shariff
authored
Feb 3, 2024
1 parent
ff0a185
commit 97d6449
Showing
10 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ target | |
.vscode | ||
|
||
# generated files | ||
.near-credentials | ||
.near-credentials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fn main() -> anyhow::Result<()> { | ||
near_workspaces::near_abi_client::Generator::new("src/gen".into()) | ||
.file("res/adder.json") | ||
.generate()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"schema_version": "0.4.0", | ||
"metadata": { | ||
"name": "abi", | ||
"version": "0.1.0", | ||
"authors": [ | ||
"Near Inc <[email protected]>" | ||
] | ||
}, | ||
"body": { | ||
"functions": [ | ||
{ | ||
"name": "add", | ||
"doc": " Adds two pairs point-wise.", | ||
"kind": "view", | ||
"params": { | ||
"serialization_type": "json", | ||
"args": [ | ||
{ | ||
"name": "a", | ||
"type_schema": { | ||
"$ref": "#/definitions/Pair" | ||
} | ||
}, | ||
{ | ||
"name": "b", | ||
"type_schema": { | ||
"$ref": "#/definitions/Pair" | ||
} | ||
} | ||
] | ||
}, | ||
"result": { | ||
"serialization_type": "json", | ||
"type_schema": { | ||
"$ref": "#/definitions/Pair" | ||
} | ||
} | ||
} | ||
], | ||
"root_schema": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "String", | ||
"type": "string", | ||
"definitions": { | ||
"Pair": { | ||
"type": "array", | ||
"items": [ | ||
{ | ||
"type": "integer", | ||
"format": "uint32", | ||
"minimum": 0.0 | ||
}, | ||
{ | ||
"type": "integer", | ||
"format": "uint32", | ||
"minimum": 0.0 | ||
} | ||
], | ||
"maxItems": 2, | ||
"minItems": 2 | ||
} | ||
} | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// This example shows how to use the `near_abi_client` Generation Based API. | ||
// We are generating client code using the schema for the ABI and and `workspaces-rs` to call into the contract. | ||
// More information about usage can be found here: <https://github.com/near/near-abi-client-rs/blob/main/README.md> | ||
// | ||
// A good scenario for usage might be when you are interacting with a contract or multiple contracts at an automated level | ||
// and you want to have a type-safe way of interacting with them. | ||
|
||
/// The generated api requires setup in the `build.rs` file to generate the client code. | ||
#[path = "gen/adder.rs"] | ||
mod generation_adder; | ||
|
||
const ADDER_WASM_FILEPATH: &str = "./examples/res/adder.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = near_workspaces::sandbox().await?; | ||
let wasm = std::fs::read(ADDER_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
// The client is initialized with the contract. | ||
let abi_client = generation_adder::AbiClient { contract }; | ||
|
||
// Here we can call the method, now typed with arguments and return types. | ||
let res = abi_client.add(vec![1, 2], vec![3, 4]).await?; | ||
|
||
assert_eq!(res, [4, 6]); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// No content here, it's to be generated on build. Here to allow cargofmt to work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// This example shows how to use the `near_abi_client` Macro Based API. | ||
// We are generating client code using the schema for the ABI and and `workspaces-rs` to call into the contract. | ||
// More information about usage can be found here: <https://github.com/near/near-abi-client-rs/blob/main/README.md> | ||
// | ||
// A good scenario for usage might be when you are interacting with a contract or multiple contracts at an automated level | ||
// and you want to have a type-safe way of interacting with them. | ||
|
||
const ADDER_WASM_FILEPATH: &str = "./examples/res/adder.wasm"; | ||
|
||
near_workspaces::near_abi_client::generate!(AbiClient for "res/adder.json"); | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = near_workspaces::sandbox().await?; | ||
let wasm = std::fs::read(ADDER_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
// The client is initialized with the contract. | ||
let abi_client = AbiClient { contract }; | ||
|
||
// Here we can call the method, now typed with arguments and return types. | ||
let res = abi_client.add(vec![1, 2], vec![3, 4]).await?; | ||
|
||
assert_eq!(res, [4, 6]); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters