-
Notifications
You must be signed in to change notification settings - Fork 52
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 all 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,42 @@ | ||
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?; | ||
|
||
// Example output: | ||
// | ||
// StateChangesInBlock RpcStateChangesInBlockResponse { | ||
// block_hash: 5SnL82tfQX1NtsSuqU5334ThZxM1B5KkUWUbeeMvVNRH, | ||
// changes: [], | ||
// } | ||
println!("StateChangesInBlock {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,52 @@ | ||
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?; | ||
|
||
// Example output: | ||
// | ||
// StateChangesInBlockByType RpcStateChangesInBlockByTypeResponse { | ||
// block_hash: 7ifRdyBsJMXVyp8zw8uGdBMaRShiXuD6yghrp66jqrst, | ||
// changes: [ | ||
// AccountTouched { | ||
// account_id: AccountId( | ||
// "dev-20230822100117-44171728969098", | ||
// ), | ||
// }, | ||
// AccessKeyTouched { | ||
// account_id: AccountId( | ||
// "dev-20230822100117-44171728969098", | ||
// ), | ||
// }, | ||
// DataTouched { | ||
// account_id: AccountId( | ||
// "dev-20230822100117-44171728969098", | ||
// ), | ||
// }, | ||
// ], | ||
// } | ||
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,87 @@ | ||
#[tokio::main] | ||
async fn main() -> anyhow::Result<()> { | ||
let worker = workspaces::sandbox().await?; | ||
|
||
// NOTE: this API is under the "experimental" flag and no guarantees are given. | ||
let genesis_config = worker.genesis_config().await?; | ||
|
||
// Example output: | ||
// | ||
// GenesisConfig GenesisConfig { | ||
// protocol_version: 60, | ||
// genesis_time: 2023-08-22T10:05:32.129104Z, | ||
// chain_id: "test-chain-5oKXo", | ||
// genesis_height: 0, | ||
// num_block_producer_seats: 50, | ||
// num_block_producer_seats_per_shard: [ | ||
// 50, | ||
// ], | ||
// avg_hidden_validator_seats_per_shard: [ | ||
// 0, | ||
// ], | ||
// dynamic_resharding: false, | ||
// protocol_upgrade_stake_threshold: Ratio { | ||
// numer: 4, | ||
// denom: 5, | ||
// }, | ||
// epoch_length: 500, | ||
// gas_limit: 1000000000000000, | ||
// min_gas_price: 100000000, | ||
// max_gas_price: 10000000000000000000000, | ||
// block_producer_kickout_threshold: 90, | ||
// chunk_producer_kickout_threshold: 90, | ||
// online_min_threshold: Ratio { | ||
// numer: 9, | ||
// denom: 10, | ||
// }, | ||
// online_max_threshold: Ratio { | ||
// numer: 99, | ||
// denom: 100, | ||
// }, | ||
// gas_price_adjustment_rate: Ratio { | ||
// numer: 1, | ||
// denom: 100, | ||
// }, | ||
// validators: [ | ||
// AccountInfo { | ||
// account_id: AccountId( | ||
// "test.near", | ||
// ), | ||
// public_key: ed25519:4Q4fpCWcsVFj3WT7xkCt45qwW84hskFB4SRMHAQfuCne, | ||
// amount: 50000000000000000000000000000000, | ||
// }, | ||
// ], | ||
// transaction_validity_period: 100, | ||
// protocol_reward_rate: Ratio { | ||
// numer: 1, | ||
// denom: 10, | ||
// }, | ||
// max_inflation_rate: Ratio { | ||
// numer: 1, | ||
// denom: 20, | ||
// }, | ||
// total_supply: 2050000000000000000000000000000000, | ||
// num_blocks_per_year: 31536000, | ||
// protocol_treasury_account: AccountId( | ||
// "test.near", | ||
// ), | ||
// fishermen_threshold: 10000000000000000000000000, | ||
// minimum_stake_divisor: 10, | ||
// shard_layout: V0( | ||
// ShardLayoutV0 { | ||
// num_shards: 1, | ||
// version: 0, | ||
// }, | ||
// ), | ||
// num_chunk_only_producer_seats: 300, | ||
// minimum_validators_per_shard: 1, | ||
// max_kickout_stake_perc: 100, | ||
// minimum_stake_ratio: Ratio { | ||
// numer: 1, | ||
// denom: 6250, | ||
// }, | ||
// use_production_config: false, | ||
// } | ||
println!("GenesisConfig {:#?}", genesis_config); | ||
Ok(()) | ||
} |
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