-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13f3a84
commit 4739705
Showing
10 changed files
with
199 additions
and
20 deletions.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Build files | ||
/target | ||
**/target | ||
Cargo.lock | ||
|
||
#include all target folders | ||
|
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
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,18 @@ | ||
use std::convert::TryFrom; | ||
|
||
use crate::error::{Error, ErrorKind}; | ||
|
||
use super::PublicKey; | ||
|
||
impl TryFrom<near_sdk::PublicKey> for PublicKey { | ||
type Error = Error; | ||
|
||
fn try_from(pk: near_sdk::PublicKey) -> Result<Self, Self::Error> { | ||
Self::try_from_bytes(pk.as_bytes()).map_err(|e| { | ||
ErrorKind::DataConversion.full( | ||
"Could not convert sdk::PublicKey into workspaces::PublicKey", | ||
e, | ||
) | ||
}) | ||
} | ||
} |
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,24 @@ | ||
[package] | ||
name = "test-contract-type-serialization" | ||
version = "0.0.0" | ||
authors = ["Near Inc <[email protected]>"] | ||
edition = "2018" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
|
||
[dependencies] | ||
anyhow = "1.0" | ||
bs58 = "0.4" | ||
near-sdk = "4.1" | ||
|
||
[profile.release] | ||
codegen-units = 1 | ||
# Tell `rustc` to optimize for small code size. | ||
opt-level = "z" | ||
lto = true | ||
debug = false | ||
panic = "abort" | ||
overflow-checks = true | ||
|
||
[workspace] |
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,4 @@ | ||
#!/bin/sh | ||
|
||
cargo build --target wasm32-unknown-unknown --release | ||
cp target/wasm32-unknown-unknown/release/test_contract_type_serialization.wasm ./res/ |
Binary file added
BIN
+355 KB
workspaces/tests/test-contracts/type-serialize/res/test_contract_type_serialization.wasm
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,41 @@ | ||
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; | ||
use near_sdk::near_bindgen; | ||
use near_sdk::{CurveType, PublicKey}; | ||
|
||
use std::convert::TryFrom; | ||
|
||
#[derive(Default, BorshSerialize, BorshDeserialize)] | ||
#[near_bindgen] | ||
struct Contract {} | ||
|
||
#[near_bindgen] | ||
impl Contract { | ||
pub fn pass_pk_back_and_forth(&self, pk: PublicKey) -> PublicKey { | ||
let mut data = vec![CurveType::ED25519 as u8]; | ||
data.extend( | ||
bs58::decode("6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp") | ||
.into_vec() | ||
.expect("could not convert bs58 to vec"), | ||
); | ||
let pk_expected = | ||
PublicKey::try_from(data).expect("could not create public key from parts"); | ||
|
||
assert_eq!(pk, pk_expected); | ||
pk | ||
} | ||
|
||
#[result_serializer(borsh)] | ||
pub fn pass_borsh_pk_back_and_forth(&self, #[serializer(borsh)] pk: PublicKey) -> PublicKey { | ||
let mut data = vec![CurveType::ED25519 as u8]; | ||
data.extend( | ||
bs58::decode("6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp") | ||
.into_vec() | ||
.expect("could not convert bs58 to vec"), | ||
); | ||
let pk_expected = | ||
PublicKey::try_from(data).expect("could not create public key from parts"); | ||
|
||
assert_eq!(pk, pk_expected); | ||
pk | ||
} | ||
} |
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