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

XDR Value Overhaul updates #516

Merged
merged 8 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 19 additions & 11 deletions Cargo.lock

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

13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,39 @@ default-members = ["cmd/soroban-cli"]
[workspace.dependencies.soroban-env-host]
version = "0.0.14"
git = "https://github.com/stellar/rs-soroban-env"
rev = "d06aaddca61f011cc64ec098b464233423197c3a"
rev = "d39dd845d5bf31f976cdfea9bc7c2f8da8396b6b"

[workspace.dependencies.soroban-spec]
version = "0.6.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "adf4870"
rev = "ab96798be9f4b77570ed032cb58743942592114a"


[workspace.dependencies.soroban-token-spec]
version = "0.6.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "adf4870"
rev = "ab96798be9f4b77570ed032cb58743942592114a"


[workspace.dependencies.soroban-sdk]
version = "0.6.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "adf4870"
rev = "ab96798be9f4b77570ed032cb58743942592114a"

[workspace.dependencies.soroban-ledger-snapshot]
version = "0.6.0"
git = "https://github.com/stellar/rs-soroban-sdk"
rev = "adf4870"
rev = "ab96798be9f4b77570ed032cb58743942592114a"

[workspace.dependencies.stellar-strkey]
version = "0.0.7"

[workspace.dependencies.sep5]
version = "0.0.2"

[workspace.dependencies.ethnum]
version = "1.3.2"


# [patch."https://github.com/stellar/rs-soroban-env"]
# soroban-env-host = { path = "../rs-soroban-env/soroban-env-host/" }
Expand Down
3 changes: 2 additions & 1 deletion cmd/soroban-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ rpassword = "7.2.0"
dirs = "4.0.0"
toml = "0.5.9"
itertools = "0.10.5"
sep5 = { workspace = true}
shlex = "1.1.0"
sep5 = { workspace = true }
ethnum = { workspace = true }


[build-dependencies]
Expand Down
10 changes: 5 additions & 5 deletions cmd/soroban-cli/src/commands/contract/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use clap::{arg, command, Parser};
use hex::FromHexError;
use rand::Rng;
use sha2::{Digest, Sha256};
use soroban_env_host::xdr::HashIdPreimageSourceAccountContractId;
use soroban_env_host::xdr::{
AccountId, ContractId, CreateContractArgs, Error as XdrError, Hash, HashIdPreimage,
HostFunction, InvokeHostFunctionOp, LedgerFootprint, LedgerKey::ContractCode,
LedgerKey::ContractData, LedgerKeyContractCode, LedgerKeyContractData, Memo, MuxedAccount,
Operation, OperationBody, Preconditions, PublicKey, ScContractCode, ScStatic, ScVal,
SequenceNumber, Transaction, TransactionEnvelope, TransactionExt, Uint256, VecM, WriteXdr,
Operation, OperationBody, Preconditions, PublicKey, ScVal, SequenceNumber, Transaction,
TransactionEnvelope, TransactionExt, Uint256, VecM, WriteXdr,
};
use soroban_env_host::xdr::{HashIdPreimageSourceAccountContractId, ScContractExecutable};
use soroban_env_host::HostError;

use crate::{
Expand Down Expand Up @@ -201,13 +201,13 @@ fn build_create_contract_tx(
body: OperationBody::InvokeHostFunction(InvokeHostFunctionOp {
function: HostFunction::CreateContract(CreateContractArgs {
contract_id: ContractId::SourceAccount(Uint256(salt)),
source: ScContractCode::WasmRef(hash.clone()),
source: ScContractExecutable::WasmRef(hash.clone()),
}),
footprint: LedgerFootprint {
read_only: vec![ContractCode(LedgerKeyContractCode { hash })].try_into()?,
read_write: vec![ContractData(LedgerKeyContractData {
contract_id: Hash(contract_id.into()),
key: ScVal::Static(ScStatic::LedgerKeyContractCode),
key: ScVal::LedgerKeyContractExecutable,
})]
.try_into()?,
},
Expand Down
21 changes: 10 additions & 11 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::{fmt::Debug, fs, io, rc::Rc};

use clap::{arg, command, Parser};
use hex::FromHexError;
use soroban_env_host::xdr::ScSpecFunctionV0;
use soroban_env_host::xdr::{ScBytes, ScContractExecutable, ScSpecFunctionV0};
use soroban_env_host::Host;
use soroban_env_host::{
budget::{Budget, CostType},
events::HostEvent,
Expand All @@ -16,12 +17,11 @@ use soroban_env_host::{
Error as XdrError, HostFunction, InvokeHostFunctionOp, InvokeHostFunctionResult,
LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount, LedgerKeyContractCode,
LedgerKeyContractData, Memo, MuxedAccount, Operation, OperationBody, OperationResult,
OperationResultTr, Preconditions, PublicKey, ReadXdr, ScContractCode,
ScHostStorageErrorCode, ScObject, ScSpecEntry, ScSpecTypeDef, ScStatic, ScStatus, ScVal,
ScVec, SequenceNumber, Transaction, TransactionEnvelope, TransactionExt,
TransactionResultResult, Uint256, VecM,
OperationResultTr, Preconditions, PublicKey, ReadXdr, ScHostStorageErrorCode, ScSpecEntry,
ScSpecTypeDef, ScStatus, ScVal, ScVec, SequenceNumber, Transaction, TransactionEnvelope,
TransactionExt, TransactionResultResult, Uint256, VecM,
},
Host, HostError,
HostError,
};
use soroban_spec::read::FromWasmError;

Expand Down Expand Up @@ -175,7 +175,7 @@ impl Cmd {

// Add the contract ID and the function name to the arguments
let mut complete_args = vec![
ScVal::Object(Some(ScObject::Bytes(contract_id.try_into().unwrap()))),
ScVal::Bytes(ScBytes(contract_id.try_into().unwrap())),
ScVal::Symbol(
function
.try_into()
Expand Down Expand Up @@ -342,7 +342,6 @@ impl Cmd {
self.build_host_function_parameters(contract_id, &spec_entries)?;

let res = h.invoke_function(HostFunction::InvokeContract(host_function_params))?;

let res_str = output_to_string(&spec, &res, &function)?;

println!("{res_str}");
Expand Down Expand Up @@ -521,13 +520,13 @@ async fn get_remote_contract_spec_entries(
let contract_ref = client
.get_ledger_entry(LedgerKey::ContractData(LedgerKeyContractData {
contract_id: xdr::Hash(*contract_id),
key: ScVal::Static(ScStatic::LedgerKeyContractCode),
key: ScVal::LedgerKeyContractExecutable,
}))
.await?;

Ok(match LedgerEntryData::from_xdr_base64(contract_ref.xdr)? {
LedgerEntryData::ContractData(ContractDataEntry {
val: ScVal::Object(Some(ScObject::ContractCode(ScContractCode::WasmRef(hash)))),
val: ScVal::ContractExecutable(ScContractExecutable::WasmRef(hash)),
..
}) => {
let contract_data = client
Expand All @@ -544,7 +543,7 @@ async fn get_remote_contract_spec_entries(
}
}
LedgerEntryData::ContractData(ContractDataEntry {
val: ScVal::Object(Some(ScObject::ContractCode(ScContractCode::Token))),
val: ScVal::ContractExecutable(ScContractExecutable::Token),
..
}) => soroban_spec::read::parse_raw(&soroban_token_spec::spec_xdr())
.map_err(FromWasmError::Parse)
Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Cmd {
.filter_map(|(k, v)| {
if let LedgerKey::ContractData(kd) = *k.clone() {
if kd.contract_id == contract_id
&& kd.key != ScVal::Static(xdr::ScStatic::LedgerKeyContractCode)
&& kd.key != ScVal::LedgerKeyContractExecutable
{
if let LedgerEntryData::ContractData(vd) = &v.data {
return Some(vd.clone());
Expand Down
18 changes: 9 additions & 9 deletions cmd/soroban-cli/src/commands/lab/token/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use soroban_env_host::{
CreateContractArgs, Error as XdrError, Hash, HashIdPreimage, HashIdPreimageFromAsset,
HostFunction, InvokeHostFunctionOp, LedgerFootprint, LedgerKey::ContractData,
LedgerKeyContractData, Memo, MuxedAccount, Operation, OperationBody, Preconditions,
PublicKey, ScContractCode, ScObject, ScStatic::LedgerKeyContractCode, ScVal,
SequenceNumber, Transaction, TransactionEnvelope, TransactionExt, Uint256, VecM, WriteXdr,
PublicKey, ScContractExecutable, ScVal, SequenceNumber, Transaction, TransactionEnvelope,
TransactionExt, Uint256, VecM, WriteXdr,
},
Host, HostError,
};
Expand Down Expand Up @@ -88,7 +88,7 @@ impl Cmd {

let res = h.invoke_function(HostFunction::CreateContract(CreateContractArgs {
contract_id: ContractId::Asset(asset.clone()),
source: ScContractCode::Token,
source: ScContractExecutable::Token,
}))?;
let res_str = utils::vec_to_hash(&res)?;

Expand Down Expand Up @@ -151,21 +151,21 @@ fn build_wrap_token_tx(
let mut read_write = vec![
ContractData(LedgerKeyContractData {
contract_id: contract_id.clone(),
key: ScVal::Static(LedgerKeyContractCode),
key: ScVal::LedgerKeyContractExecutable,
}),
ContractData(LedgerKeyContractData {
contract_id: contract_id.clone(),
key: ScVal::Object(Some(ScObject::Vec(
key: ScVal::Vec(Some(
vec![ScVal::Symbol("Metadata".try_into().unwrap())].try_into()?,
))),
)),
}),
];
if asset != &Asset::Native {
read_write.push(ContractData(LedgerKeyContractData {
contract_id: contract_id.clone(),
key: ScVal::Object(Some(ScObject::Vec(
key: ScVal::Vec(Some(
vec![ScVal::Symbol("Admin".try_into().unwrap())].try_into()?,
))),
)),
}));
}

Expand All @@ -174,7 +174,7 @@ fn build_wrap_token_tx(
body: OperationBody::InvokeHostFunction(InvokeHostFunctionOp {
function: HostFunction::CreateContract(CreateContractArgs {
contract_id: ContractId::Asset(asset.clone()),
source: ScContractCode::Token,
source: ScContractExecutable::Token,
}),
footprint: LedgerFootprint {
read_only: VecM::default(),
Expand Down
Loading