-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose experimental apis #285
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
de203d5
feat: expose experimantal apis
9cc0622
feat: impl apis on sandbox
040e5f0
fix: impl for client
eb6ab8f
fix: revert unrelated changes
3908730
feat: impl api with trial test
689ddd1
upd: adding expt api examples
567edee
upd: include left expt examples
356d035
upd: using Option for args
4173862
upd: add examples & change tx_status
ff88645
chore: clippy fixes and fmt
62f9000
Merge branch 'main' into feat/expose-expt-rpc-apis
7898757
upd: address review
c0893d4
Merge branch 'main' into feat/expose-expt-rpc-apis
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,36 @@ | ||
use near_primitives::{types::BlockReference, views::StateChangesRequestView}; | ||
use serde_json::json; | ||
|
||
const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let outcome = contract | ||
.call("set_status") | ||
.args_json(json!({ | ||
"message": "hello_world", | ||
})) | ||
.transact() | ||
.await?; | ||
|
||
let block_ref = { | ||
let hash = near_primitives::hash::CryptoHash(outcome.outcome().block_hash.0); | ||
BlockReference::BlockId(near_primitives::types::BlockId::Hash(hash)) | ||
}; | ||
|
||
let state_changes = { | ||
StateChangesRequestView::ContractCodeChanges { | ||
account_ids: vec![contract.id().clone()], | ||
} | ||
}; | ||
|
||
// NOTE: this API is under the "experimental" flag and no guarantees are given. | ||
let res = worker.changes(block_ref, state_changes).await?; | ||
|
||
println!("StateChangesInBlock {res:?}"); | ||
frol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,30 @@ | ||
use near_primitives::types::BlockReference; | ||
use serde_json::json; | ||
|
||
const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let outcome = contract | ||
.call("set_status") | ||
.args_json(json!({ | ||
"message": "hello_world", | ||
})) | ||
.transact() | ||
.await?; | ||
|
||
let block_ref = { | ||
let hash = near_primitives::hash::CryptoHash(outcome.outcome().block_hash.0); | ||
BlockReference::BlockId(near_primitives::types::BlockId::Hash(hash)) | ||
}; | ||
|
||
// NOTE: this API is under the "experimental" flag and no guarantees are given. | ||
let res = worker.changes_in_block(block_ref).await?; | ||
|
||
println!("StateChangesInBlockByType {res:?}"); | ||
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,33 @@ | ||
use serde_json::json; | ||
|
||
const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let (fn_name, fn_args) = ("set_status", json!({ "message": "hello_world"})); | ||
|
||
let _outcome = contract | ||
.call(fn_name) | ||
.args_json(fn_args.clone()) | ||
.transact() | ||
.await?; | ||
|
||
let signed_tx = worker | ||
.signed_transaction( | ||
contract.id(), | ||
contract.signer(), | ||
fn_name.to_string(), | ||
fn_args, | ||
) | ||
.await?; | ||
|
||
// NOTE: this API is under the "experimental" flag and no guarantees are given. | ||
let resp = worker.check_tx(signed_tx).await?; | ||
|
||
println!("RpcBroadcastTxSyncResponse {resp:?}"); | ||
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,11 @@ | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
|
||
// NOTE: this API is under the "experimental" flag. | ||
let genesis_config = worker.genesis_config().await?; | ||
|
||
// dump the genesis config info to stdout | ||
println!("Genesis Config {:?}", genesis_config); | ||
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,29 @@ | ||
const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let outcome = contract | ||
.call("set_status") | ||
.args_json(serde_json::json!({ | ||
"message": "hello_world", | ||
})) | ||
.transact() | ||
.await?; | ||
|
||
let block_reference = { | ||
let hash = outcome.outcome().block_hash; | ||
near_primitives::types::BlockReference::BlockId(near_primitives::types::BlockId::Hash( | ||
near_primitives::hash::CryptoHash(hash.0), | ||
)) | ||
}; | ||
|
||
// NOTE: this API is under the "experimental" flag. | ||
let protocol_config = worker.protocol_config(block_reference).await?; | ||
|
||
println!("Protocol Config {protocol_config:?}"); | ||
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,40 @@ | ||
use near_jsonrpc_primitives::types::receipts::ReceiptReference; | ||
|
||
const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let outcome = contract | ||
.call("set_status") | ||
.args_json(serde_json::json!({ | ||
"message": "hello_world", | ||
})) | ||
.transact() | ||
.await?; | ||
|
||
let receipt_ref = { | ||
let mut ids = outcome.outcome().receipt_ids.clone(); | ||
if ids.is_empty() { | ||
println!("no receipt ids present"); | ||
return Ok(()); | ||
} | ||
|
||
println!("receipts found: {ids:?}"); | ||
|
||
ReceiptReference { | ||
receipt_id: near_primitives::hash::CryptoHash( | ||
ids.pop().expect("expected at least one receipt id").0, | ||
), | ||
} | ||
}; | ||
|
||
// NOTE: this API is under the "experimental" flag and no guarantees are given. | ||
let resp = worker.receipt(receipt_ref).await?; | ||
Comment on lines
+19
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to expose the fact that we're using |
||
|
||
println!("ReceiptView: {resp:?}"); | ||
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,35 @@ | ||
use near_jsonrpc_primitives::types::transactions::TransactionInfo; | ||
use serde_json::json; | ||
|
||
const STATUS_MSG_WASM_FILEPATH: &str = "./examples/res/status_message.wasm"; | ||
|
||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
let wasm = std::fs::read(STATUS_MSG_WASM_FILEPATH)?; | ||
let contract = worker.dev_deploy(&wasm).await?; | ||
|
||
let outcome = contract | ||
.call("set_status") | ||
.args_json(json!({ | ||
"message": "hello_world", | ||
})) | ||
.transact() | ||
.await?; | ||
|
||
println!("set_status: {:?}", outcome); | ||
|
||
let tx_info = { | ||
let outcome = outcome.outcome(); | ||
TransactionInfo::TransactionId { | ||
hash: near_primitives::hash::CryptoHash(outcome.block_hash.0), | ||
frol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
account_id: outcome.executor_id.clone(), | ||
} | ||
}; | ||
|
||
// NOTE: this API is under the "experimental" flag and no guarantees are given. | ||
let resp = worker.tx_status(tx_info).await?; | ||
|
||
println!("FinalExecutionOutcomeWithReceiptView {resp:?}"); | ||
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,10 @@ | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
|
||
// NOTE: this API is under the "experimental" flag. | ||
let validators = worker.validators_ordered(None).await?; | ||
|
||
println!("Validators {validators:?}"); | ||
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this one and consistency with
Query
struct. We only need to supplystate_changes
while further methods can supplyblock_ref
if it's needed withFinality::Final
being the default when not supplied