-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
7fbb526
commit 2a0be14
Showing
6 changed files
with
75 additions
and
6 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
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,40 @@ | ||
// #region script-init | ||
import type { BigNumberish } from 'fuels'; | ||
import { arrayify, Provider, ReceiptType, ScriptRequest, Wallet } from 'fuels'; | ||
|
||
import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../env'; | ||
import { CallTestScript } from '../typegend'; | ||
|
||
const provider = await Provider.create(LOCAL_NETWORK_URL); | ||
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider); | ||
const script = new CallTestScript(wallet); | ||
|
||
type MyStruct = { | ||
arg_one: boolean; | ||
arg_two: BigNumberish; | ||
}; | ||
|
||
const scriptRequest = new ScriptRequest( | ||
CallTestScript.bytecode, | ||
(myStruct: MyStruct) => { | ||
const encoded = script.interface.functions.main.encodeArguments([myStruct]); | ||
|
||
return arrayify(encoded); | ||
}, | ||
(scriptResult) => { | ||
if (scriptResult.returnReceipt.type === ReceiptType.Revert) { | ||
throw new Error('Reverted'); | ||
} | ||
if (scriptResult.returnReceipt.type !== ReceiptType.ReturnData) { | ||
throw new Error('fail'); | ||
} | ||
|
||
const [decodedResult] = script.interface.functions.main.decodeOutput( | ||
scriptResult.returnReceipt.data | ||
); | ||
return decodedResult; | ||
} | ||
); | ||
// #endregion script-init | ||
|
||
console.log('Script request should be defined', scriptRequest); |
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,6 +1,7 @@ | ||
[workspace] | ||
members = [ | ||
"bytecode-input", | ||
"call-test-script", | ||
"configurable-pin", | ||
"counter", | ||
"echo-asset-id", | ||
|
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,6 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
license = "Apache-2.0" | ||
name = "call-test-script" | ||
|
||
[dependencies] |
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,27 @@ | ||
script; | ||
|
||
fn log<T>(v: T) { | ||
asm(r1: v) { | ||
log r1 zero zero zero; | ||
} | ||
} | ||
|
||
fn logd<T>(v: T) { | ||
asm(r1: v, r2: __size_of::<T>()) { | ||
logd zero zero r1 r2; | ||
} | ||
} | ||
|
||
struct MyStruct { | ||
arg_one: bool, | ||
arg_two: u64, | ||
} | ||
|
||
fn main(my_struct: MyStruct) -> MyStruct { | ||
log(my_struct.arg_one); | ||
log(my_struct.arg_two); | ||
MyStruct { | ||
arg_one: my_struct.arg_one, | ||
arg_two: my_struct.arg_two, | ||
} | ||
} |
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