From a064695973c6c4afb1a57966b3d14555c4ca150c Mon Sep 17 00:00:00 2001 From: samliok Date: Thu, 21 Dec 2023 21:54:10 -0500 Subject: [PATCH 1/2] rename call_program --- .../examples/imports/program/program.go | 3 +-- x/programs/examples/testdata/counter.wasm | Bin 37537 -> 37332 bytes x/programs/examples/testdata/token.wasm | Bin 36782 -> 36765 bytes x/programs/rust/examples/counter/src/lib.rs | 12 ++++++------ .../rust/wasmlanche_sdk/src/host/program.rs | 11 ++++------- x/programs/rust/wasmlanche_sdk/src/program.rs | 10 +++++----- 6 files changed, 16 insertions(+), 20 deletions(-) diff --git a/x/programs/examples/imports/program/program.go b/x/programs/examples/imports/program/program.go index 1ef54baad7..d3d196e939 100644 --- a/x/programs/examples/imports/program/program.go +++ b/x/programs/examples/imports/program/program.go @@ -62,11 +62,10 @@ func (i *Import) Register(link runtime.Link, meter runtime.Meter, imports runtim // callProgramFn makes a call to an entry function of a program in the context of another program's ID. func (i *Import) callProgramFn( caller *wasmtime.Caller, - callerID int64, programID int64, - maxUnits int64, function int64, args int64, + maxUnits int64, ) int64 { ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/x/programs/examples/testdata/counter.wasm b/x/programs/examples/testdata/counter.wasm index 8ad9f2c730de7e19ef038b71bc71f7063667eedf..4ecbb2c5968d51481f245067bfb98d9f2e039c36 100755 GIT binary patch delta 3517 zcmb7GU1%Id9G{(?{kYrPWb@hUU7F6UEnaBTq)_idRm>bsn_>m=se%s?Mas59pb9~- zd)6rNyWvC>d{9&>Vl5hkJ_hl@2f>Pc5qwY(^}z?hDt!?2_n*B@HuZy=kj(7NfBv7p z`Tyq4cledJc$wXQ`eBPPX1%srR+d<;6mAaHvgrCN-VU0G-Oifr9=s7 zPcWvOiWT7K>z(xuYw|Hnd6QQ$L<#;?ljwQU*M^|v6Lu6oV733Wo@|SILYxzGp=G4> zRXVQ+qZcyk6LwXRUTL*#QU*QG(2n+$AcIUgE!)>6C1@@VGR9}gMSl+N*=ryB7p?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Uc;Th^eTpjj6nUDRj6v9ihrQpcHT?FDP$=z-9nry7y1FCIYndQ z$BxX>1{~3b%-W941u@b_Q#Gbn;H05~`mpj>*=6Lw2hIit+`Bb!<}tF(B!ov;`#4`; z1$TL%nzcWp0K%;z9+8~jy_cgIti21De;!T*)Eh!0e=S;vJF)X}RE;)kpIihX=K89me~fhQd8wwJLK~SKFbseha4ccwy2nTmYBu)i_kuH zV?&$-4mFinF;sZ%yy8NM6}CC#9g5Gmi>$j?j40rU%ExY;pkyQAksx3w3YU&SsIXq) z9e@dREg!Mv15gLcj8SC7N3P@}LXJ@dcKARr;=*`ui%Ta<9xiI?Pt^K^FqB0_*k_K* zQS44Gu21rqoB&^z%6WlXca z!!7LvuUjQSxy#Wfor?y~sx9tt97YWnpt~cB66C{^ctf!&`<+w@uKJL`wu|3ejF^}c|5p*kN7Ty$h;=P z_sU;JOSxay0EbfWGWw7J-o+5D(!3#TU$IFa#rqkOnCQHHF014CmN<#QSf}&>s7>n7 zho49XFp~NyQOcHDl*8Vt7Lf#jVHc}4up>z@#t7h m!AX-sWcwzJ@^`&(I$ULRl$zM~5aoy|@ZP1-Kb#xie))gkwuQ0) diff --git a/x/programs/rust/examples/counter/src/lib.rs b/x/programs/rust/examples/counter/src/lib.rs index e94fff17b0..32f6d66cfa 100644 --- a/x/programs/rust/examples/counter/src/lib.rs +++ b/x/programs/rust/examples/counter/src/lib.rs @@ -41,14 +41,14 @@ fn inc(program: Program, to: Address, amount: i64) -> bool { /// Increments the count at the address by the amount for an external program. #[public] fn inc_external( - program: Program, + _: Program, target: Program, max_units: i64, of: Address, amount: i64, ) -> i64 { - program - .call_program(&target, max_units, "inc", params!(&of, &amount)) + target + .call_function("inc", params!(&of, &amount), max_units) .unwrap() } @@ -63,8 +63,8 @@ fn get_value(program: Program, of: Address) -> i64 { /// Gets the count at the address for an external program. #[public] -fn get_value_external(program: Program, target: Program, max_units: i64, of: Address) -> i64 { - program - .call_program(&target, max_units, "get_value", params!(&of)) +fn get_value_external(_: Program, target: Program, max_units: i64, of: Address) -> i64 { + target + .call_function("get_value", params!(&of), max_units) .unwrap() } diff --git a/x/programs/rust/wasmlanche_sdk/src/host/program.rs b/x/programs/rust/wasmlanche_sdk/src/host/program.rs index df61db4ccf..8a91badbde 100644 --- a/x/programs/rust/wasmlanche_sdk/src/host/program.rs +++ b/x/programs/rust/wasmlanche_sdk/src/host/program.rs @@ -7,26 +7,23 @@ use crate::program::Program; extern "C" { #[link_name = "call_program"] fn _call_program( - caller_id: i64, target_id: i64, - max_units: i64, function: i64, args_ptr: i64, + max_units: i64, ) -> i64; } -/// Calls another program `target` and returns the result. +/// Calls a program `target` and returns the result. pub(crate) fn call( - caller: &Program, target: &Program, - max_units: i64, function_name: &str, args: &[u8], + max_units: i64, ) -> Result { - let caller = to_smart_ptr(caller.id())?; let target = to_smart_ptr(target.id())?; let function = to_smart_ptr(function_name.as_bytes())?; let args = to_smart_ptr(args)?; - Ok(unsafe { _call_program(caller, target, max_units, function, args) }) + Ok(unsafe { _call_program(target, function, args, max_units) }) } diff --git a/x/programs/rust/wasmlanche_sdk/src/program.rs b/x/programs/rust/wasmlanche_sdk/src/program.rs index a25606cb9a..a65469bf84 100644 --- a/x/programs/rust/wasmlanche_sdk/src/program.rs +++ b/x/programs/rust/wasmlanche_sdk/src/program.rs @@ -29,21 +29,21 @@ impl Program { State::new(Program::new(*self.id())) } - /// Attempts to call another program `target` from this program `caller`. + /// Attempts to call a function `name` with `args` on the given program. This method + /// is used to call functions on external programs. /// # Errors /// Returns a `StateError` if the call fails. /// # Safety /// The caller must ensure that `function_name` + `args` point to valid memory locations. - pub fn call_program( + pub fn call_function( &self, - target: &Program, - max_units: i64, function_name: &str, args: Vec>, + max_units: i64, ) -> Result { // flatten the args into a single byte vector let args = args.into_iter().flatten().collect::>(); - call_program(self, target, max_units, function_name, &args) + call_program(self, function_name, &args, max_units) } } From 438e64ba11392df6b9807175cf865d4eb0cbe5f8 Mon Sep 17 00:00:00 2001 From: samliok Date: Thu, 21 Dec 2023 22:10:16 -0500 Subject: [PATCH 2/2] =?UTF-8?q?cargo=20fmt=20=F0=9F=98=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- x/programs/rust/examples/counter/src/lib.rs | 8 +------- x/programs/rust/wasmlanche_sdk/src/host/program.rs | 7 +------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/x/programs/rust/examples/counter/src/lib.rs b/x/programs/rust/examples/counter/src/lib.rs index 32f6d66cfa..65bcaa2a1e 100644 --- a/x/programs/rust/examples/counter/src/lib.rs +++ b/x/programs/rust/examples/counter/src/lib.rs @@ -40,13 +40,7 @@ fn inc(program: Program, to: Address, amount: i64) -> bool { /// Increments the count at the address by the amount for an external program. #[public] -fn inc_external( - _: Program, - target: Program, - max_units: i64, - of: Address, - amount: i64, -) -> i64 { +fn inc_external(_: Program, target: Program, max_units: i64, of: Address, amount: i64) -> i64 { target .call_function("inc", params!(&of, &amount), max_units) .unwrap() diff --git a/x/programs/rust/wasmlanche_sdk/src/host/program.rs b/x/programs/rust/wasmlanche_sdk/src/host/program.rs index 8a91badbde..fe5bc69e87 100644 --- a/x/programs/rust/wasmlanche_sdk/src/host/program.rs +++ b/x/programs/rust/wasmlanche_sdk/src/host/program.rs @@ -6,12 +6,7 @@ use crate::program::Program; #[link(wasm_import_module = "program")] extern "C" { #[link_name = "call_program"] - fn _call_program( - target_id: i64, - function: i64, - args_ptr: i64, - max_units: i64, - ) -> i64; + fn _call_program(target_id: i64, function: i64, args_ptr: i64, max_units: i64) -> i64; } /// Calls a program `target` and returns the result.