Skip to content

Commit

Permalink
Decouple gateway response types from internal types + custom type con…
Browse files Browse the repository at this point in the history
…vertor for native Sui move types (MystenLabs#1855)

* using custom type mirroring MoveStruct and MoveValue to control serde

* add convertor for native Sui types

* fix test
convert bytearray type

* decouple gateway response type and internal message types

* added types for certifiedTransaction

* * Removed json_schema.rs
* lot of clean up

* * Remove unnecessary wrapping `SignedTransaction`

* camelCase fixes

* address PR comments

* rename contents to fields to make the struct consistent

* update openrpc.json

* * add unit test for sui_json bcs parser
* add unit test for gateway type move value to sui move value conversion
* Fix a bug in Coin type layout

* fixup after rebase

* * added serde test for SuiMoveValue
* make SuiMoveValue externally tagged to remove ambiguity

* condense SuiMoveValue enum types to avoid serde ambiguity, instead of using tags.
  • Loading branch information
patrickkuo authored May 16, 2022
1 parent 976b6bb commit cf65cfe
Show file tree
Hide file tree
Showing 42 changed files with 2,240 additions and 2,144 deletions.
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ tower = { version = "0.4.12", features = ["util", "timeout", "load-shed", "limit

sui = { path = "../sui" }
sui-types = { path = "../sui_types" }
sui_core = { path = "../sui_core" }

[dev-dependencies]
tempfile = "3.3.0"
Expand Down
10 changes: 5 additions & 5 deletions faucet/src/faucet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
use crate::FaucetError;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use sui_core::gateway_types::SuiObject;
use sui_types::{
base_types::{ObjectID, SuiAddress},
gas_coin::GasCoin,
object::Object,
};

mod simple_faucet;
Expand All @@ -33,16 +33,16 @@ pub trait Faucet {
) -> Result<FaucetReceipt, FaucetError>;
}

impl<'a> FromIterator<&'a Object> for FaucetReceipt {
fn from_iter<T: IntoIterator<Item = &'a Object>>(iter: T) -> Self {
impl<'a> FromIterator<&'a SuiObject> for FaucetReceipt {
fn from_iter<T: IntoIterator<Item = &'a SuiObject>>(iter: T) -> Self {
FaucetReceipt {
sent: iter.into_iter().map(|o| o.into()).collect(),
}
}
}

impl From<&Object> for CoinInfo {
fn from(v: &Object) -> Self {
impl From<&SuiObject> for CoinInfo {
fn from(v: &SuiObject) -> Self {
let gas_coin = GasCoin::try_from(v).unwrap();
Self {
amount: gas_coin.value(),
Expand Down
16 changes: 8 additions & 8 deletions faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
use anyhow::anyhow;
use async_trait::async_trait;
use sui::wallet_commands::WalletContext;
use sui_core::gateway_types::{SuiExecutionStatus, SuiObject};
use sui_types::{
base_types::{ObjectID, SuiAddress},
gas_coin::GasCoin,
messages::{ExecutionStatus, Transaction},
object::Object,
messages::Transaction,
};
use tracing::info;

Expand Down Expand Up @@ -66,7 +66,7 @@ impl SimpleFaucet {
})
}

async fn get_coins(&self, amounts: &[u64]) -> Result<Vec<Object>, FaucetError> {
async fn get_coins(&self, amounts: &[u64]) -> Result<Vec<SuiObject>, FaucetError> {
let result = self
.split_coins(
amounts,
Expand Down Expand Up @@ -107,7 +107,7 @@ impl SimpleFaucet {
gas_object_id: ObjectID,
signer: SuiAddress,
budget: u64,
) -> Result<Vec<Object>, anyhow::Error> {
) -> Result<Vec<SuiObject>, anyhow::Error> {
// TODO: move this function to impl WalletContext{} and reuse in wallet_commands
let context = &self.wallet;
let data = context
Expand Down Expand Up @@ -153,13 +153,13 @@ impl SimpleFaucet {
.read()
.unwrap()
.sign(&signer, &data.to_bytes())?;
let (_cert, effects) = context
let effects = context
.gateway
.execute_transaction(Transaction::new(data, signature))
.await?
.to_effect_response()?;

if matches!(effects.status, ExecutionStatus::Failure { .. }) {
.to_effect_response()?
.effects;
if matches!(effects.status, SuiExecutionStatus::Failure { .. }) {
return Err(anyhow!("Error transferring object: {:#?}", effects.status));
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions sui/open_rpc/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ pub fn open_rpc(attr: TokenStream, item: TokenStream) -> TokenStream {
for (name, ty) in method.params {
let (ty, required) = extract_type_from_option(ty);
inputs.push(quote! {
let des = builder.create_content_descriptor::<#ty>(#name, "", "", #required);
let des = builder.create_content_descriptor::<#ty>(#name, None, None, #required);
inputs.push(des);
})
}
let returns_ty = if let Some(ty) = method.returns {
let (ty, required) = extract_type_from_option(ty);
let name = quote! {#ty}.to_string();
quote! {Some(builder.create_content_descriptor::<#ty>(#name, "", "", #required));}
quote! {Some(builder.create_content_descriptor::<#ty>(#name, None, None, #required));}
} else {
quote! {None;}
};
Expand Down
Loading

0 comments on commit cf65cfe

Please sign in to comment.