Skip to content

Commit

Permalink
Merge pull request #3553 from sisuresh/pass-source
Browse files Browse the repository at this point in the history
Pass the source account into the host and allow calling into the token wrapper host functions

Reviewed-by: graydon
  • Loading branch information
latobarita authored Sep 28, 2022
2 parents 39bee1a + 060a6bb commit d3b8061
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 120 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
members = ["src/rust"]

[patch.crates-io]
stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "cebf5259" }
stellar-xdr = { git = "https://github.com/stellar/rs-stellar-xdr", rev = "f87409c" }
wasmi = { package = "soroban-wasmi", git = "https://github.com/stellar/wasmi", rev = "a61b6df" }
soroban-env-common = { git = "https://github.com/stellar/rs-soroban-env", rev = "4aabfbf" }
soroban-native-sdk-macros = { git = "https://github.com/stellar/rs-soroban-env", rev = "4aabfbf" }
soroban-env-common = { git = "https://github.com/stellar/rs-soroban-env", rev = "96d7a04" }
soroban-native-sdk-macros = { git = "https://github.com/stellar/rs-soroban-env", rev = "96d7a04" }


2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.63"
channel = "1.64"
2 changes: 1 addition & 1 deletion src/protocol-next/xdr
Submodule xdr updated from d194cc to 161e2e
4 changes: 2 additions & 2 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cxx = "1.0"
im-rc = "15.0.0"
base64 = "0.13.0"
rustc-simple-version = "0.1.0"
soroban-env-host = { git = "https://github.com/stellar/rs-soroban-env", rev = "4aabfbf", features = [
soroban-env-host = { git = "https://github.com/stellar/rs-soroban-env", rev = "96d7a04", features = [
"vm",
] }
soroban-test-wasms = { git = "https://github.com/stellar/rs-soroban-env", rev = "4aabfbf" }
soroban-test-wasms = { git = "https://github.com/stellar/rs-soroban-env", rev = "96d7a04" }
21 changes: 8 additions & 13 deletions src/rust/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use soroban_env_host::{
storage::{self, AccessType, SnapshotSource, Storage},
xdr,
xdr::{
HostFunction, LedgerEntry, LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyAccount,
LedgerKeyContractData, LedgerKeyTrustLine, ReadXdr, ScHostContextErrorCode,
ScUnknownErrorCode, ScVec, WriteXdr, XDR_FILES_SHA256,
AccountId, HostFunction, LedgerEntry, LedgerEntryData, LedgerFootprint, LedgerKey,
LedgerKeyAccount, LedgerKeyContractData, LedgerKeyTrustLine, ReadXdr,
ScHostContextErrorCode, ScUnknownErrorCode, ScVec, WriteXdr, XDR_FILES_SHA256,
},
Host, HostError, MeteredOrdMap,
};
Expand Down Expand Up @@ -194,29 +194,24 @@ pub(crate) fn invoke_host_function(
hf_buf: &XDRBuf,
args_buf: &XDRBuf,
footprint_buf: &XDRBuf,
source_account_buf: &XDRBuf,
ledger_entries: &Vec<XDRBuf>,
) -> Result<Vec<Bytes>, Box<dyn Error>> {
let budget = Budget::default();
let hf = xdr_from_xdrbuf::<HostFunction>(&hf_buf)?;
let args = xdr_from_xdrbuf::<ScVec>(&args_buf)?;
let source_account = xdr_from_xdrbuf::<AccountId>(&source_account_buf)?;

let footprint = build_storage_footprint_from_xdr(budget.clone(), footprint_buf)?;
let map =
build_storage_map_from_xdr_ledger_entries(budget.clone(), &footprint, ledger_entries)?;

let storage = Storage::with_enforcing_footprint_and_map(footprint, map);
let host = Host::with_storage_and_budget(storage, budget);
host.set_source_account(source_account);

match hf {
HostFunction::Call => {
info!(target: TX, "Invoking host function 'Call'");
host.invoke_function(hf, args)?;
}
HostFunction::CreateContract => {
info!(target: TX, "Invoking host function 'CreateContract'");
host.invoke_function(hf, args)?;
}
};
info!(target: TX, "Invoking host function {}", hf.to_string());
host.invoke_function(hf, args)?;

let (storage, _budget, _events) = host
.try_finish()
Expand Down
1 change: 1 addition & 0 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod rust_bridge {
hf_buf: &XDRBuf,
args: &XDRBuf,
footprint: &XDRBuf,
source_account: &XDRBuf,
ledger_entries: &Vec<XDRBuf>,
) -> Result<Vec<Bytes>>;
fn preflight_host_function(
Expand Down
3 changes: 2 additions & 1 deletion src/transactions/InvokeHostFunctionOpFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ InvokeHostFunctionOpFrame::doApply(AbstractLedgerTxn& ltx)
retBufs = rust_bridge::invoke_host_function(
toXDRBuf(mInvokeHostFunction.function),
toXDRBuf(mInvokeHostFunction.parameters),
toXDRBuf(mInvokeHostFunction.footprint), ledgerEntryXdrBufs);
toXDRBuf(mInvokeHostFunction.footprint), toXDRBuf(getSourceID()),
ledgerEntryXdrBufs);
}
catch (std::exception&)
{
Expand Down
Loading

0 comments on commit d3b8061

Please sign in to comment.