Skip to content
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(ext): add app-side library for NEAR #374

Merged
merged 43 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
a851290
feat: add a fetch function inside the runtime host environment
saeed-zil Jun 12, 2024
052f4ed
Add headers
saeed-zil Jun 12, 2024
ad06f97
Add method
saeed-zil Jun 12, 2024
5279d24
Add body
saeed-zil Jun 12, 2024
16b37ae
feat: Add app-side library for NEAR
saeed-zil Jun 13, 2024
a6fbc46
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 18, 2024
7bef965
code review fixes
saeed-zil Jun 18, 2024
a63bc2b
Fix serde deserializer
saeed-zil Jun 18, 2024
854b6fe
Remove unwrap
saeed-zil Jun 18, 2024
22741e2
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 18, 2024
893c6c6
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 18, 2024
3d38742
Add methods
saeed-zil Jun 18, 2024
66d3042
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 19, 2024
96e6c6a
Move AltResult to primitives.
saeed-zil Jun 19, 2024
6bd911d
Make id incremental
saeed-zil Jun 19, 2024
222ae8d
Make view account more restricted.
saeed-zil Jun 19, 2024
792de59
Fix code style
saeed-zil Jun 19, 2024
4ed7b77
Add more query functions
saeed-zil Jun 20, 2024
b13f56f
add function call.
saeed-zil Jun 21, 2024
93d3144
change comment
saeed-zil Jun 21, 2024
9f9cf2d
Update style
saeed-zil Jun 21, 2024
a587f32
fix code style
saeed-zil Jun 21, 2024
c1c0f72
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 24, 2024
034a9eb
update cargo.lock
saeed-zil Jun 24, 2024
cd4b7d2
Code review fixes
saeed-zil Jun 24, 2024
c16ac26
Add error type for rpc calls.
saeed-zil Jun 24, 2024
3901d33
Change the design
saeed-zil Jun 24, 2024
17c0563
minor changes
saeed-zil Jun 24, 2024
4455f4b
unwanted change
saeed-zil Jun 24, 2024
364fc0d
remove useless code
saeed-zil Jun 24, 2024
6202fe1
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 24, 2024
38d146f
tiny fixes
saeed-zil Jun 24, 2024
93070fd
rename error.
saeed-zil Jun 24, 2024
961cf9f
Merge client and jsonrpcclient
saeed-zil Jun 24, 2024
8ffddab
make id a number.
saeed-zil Jun 24, 2024
aa2cfa2
fix error
saeed-zil Jun 24, 2024
424555e
Merge branch 'master' of github.com:calimero-network/core into 370-ad…
saeed-zil Jun 26, 2024
1b4474e
Add more error types.
saeed-zil Jun 26, 2024
104cb64
Merge branch 'master' into 370-add-near-app-side-library
its-saeed Jun 26, 2024
fd718f7
move code to better mods
saeed-zil Jun 26, 2024
5559c99
Update crates/runtime/src/logic.rs
its-saeed Jun 26, 2024
885a36f
Add an example for near library
saeed-zil Jun 26, 2024
3722fd6
Merge branch '370-add-near-app-side-library' of github.com:calimero-n…
saeed-zil Jun 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/sdk/libs/near/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl Client {
}
}

pub fn call<M>(&self, method: M) -> Result<M::Response, Error<RpcError<M::Error>>>
pub fn call<M>(&self, method: M) -> Result<M::Response, Error<M::Error>>
where
M: RpcMethod,
{
Expand All @@ -42,9 +42,9 @@ impl Client {
let response = unsafe { env::ext::fetch(&self.url, "POST", &headers, &body) }
.map_err(Error::FetchError)?;

serde_json::from_slice::<Response<M::Response, RpcError<M::Error>>>(&response)?
serde_json::from_slice::<Response<M::Response, M::Error>>(&response)?
its-saeed marked this conversation as resolved.
Show resolved Hide resolved
.data
.map_err(|e| Error::ServerError(e))
.map_err(Error::ServerError)
}
}

Expand Down
62 changes: 2 additions & 60 deletions crates/sdk/libs/near/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,70 +1,12 @@
use serde_json::json;

use crate::types::{AccountId, BlockHash, BlockHeight, BlockId, BlockReference, ShardId};
use crate::types::{BlockHash, BlockHeight, BlockId};
use crate::views::{
AccessKeyList, AccessKeyView, AccountView, CallResult, ContractCodeView, QueryRequest,
ViewStateResult,
};
use crate::RpcMethod;

#[derive(thiserror::Error, Debug, serde::Serialize, serde::Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcQueryError {
#[error("There are no fully synchronized blocks on the node yet")]
NoSyncedBlocks,
#[error("The node does not track the shard ID {requested_shard_id}")]
UnavailableShard { requested_shard_id: ShardId },
#[error(
"The data for block #{block_height} is garbage collected on this node, use an archival node to fetch historical data"
)]
GarbageCollectedBlock {
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error("Block either has never been observed on the node or has been garbage collected: {block_reference:?}")]
UnknownBlock { block_reference: BlockReference },
#[error("Account ID {requested_account_id} is invalid")]
InvalidAccount {
requested_account_id: AccountId,
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error("account {requested_account_id} does not exist while viewing")]
UnknownAccount {
requested_account_id: AccountId,
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error(
"Contract code for contract ID #{contract_account_id} has never been observed on the node"
)]
NoContractCode {
contract_account_id: AccountId,
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error("State of contract {contract_account_id} is too large to be viewed")]
TooLargeContractState {
contract_account_id: AccountId,
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error("Access key for public key {public_key} has never been observed on the node")]
UnknownAccessKey {
public_key: String,
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error("Function call returned an error: {vm_error}")]
ContractExecutionError {
vm_error: String,
block_height: BlockHeight,
block_hash: calimero_primitives::hash::Hash,
},
#[error("The node reached its limits. Try again later. More details: {error_message}")]
InternalError { error_message: String },
}

#[derive(serde::Serialize, Debug)]
pub struct RpcQueryRequest {
pub block_id: BlockId,
Expand Down Expand Up @@ -93,7 +35,7 @@ pub enum QueryResponseKind {

impl RpcMethod for RpcQueryRequest {
type Response = RpcQueryResponse;
type Error = RpcQueryError;
miraclx marked this conversation as resolved.
Show resolved Hide resolved
type Error = String;
its-saeed marked this conversation as resolved.
Show resolved Hide resolved

fn method_name(&self) -> &str {
"query"
Expand Down
27 changes: 0 additions & 27 deletions crates/sdk/libs/near/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub type AccountId = near_account_id::AccountId;
pub type StorageUsage = u64;
pub type Nonce = u64;
pub type Balance = u128;
pub type ShardId = u64;

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
Expand All @@ -16,32 +15,6 @@ pub enum BlockId {
Hash(BlockHash),
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BlockReference {
BlockId(BlockId),
Finality(Finality),
SyncCheckpoint(SyncCheckpoint),
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum SyncCheckpoint {
Genesis,
EarliestAvailable,
}

#[derive(serde::Serialize, serde::Deserialize, Default, Clone, Debug)]
pub enum Finality {
#[serde(rename = "optimistic")]
None,
#[serde(rename = "near-final")]
DoomSlug,
#[serde(rename = "final")]
#[default]
Final,
}

#[serde_as]
#[derive(serde::Deserialize, Clone, Debug)]
#[serde(transparent)]
Expand Down