Skip to content

Commit

Permalink
Fix Vec support for Fuel (#206)
Browse files Browse the repository at this point in the history
* Add script to call Sway contract methods

* Fix Vec type

* Update rescript-schema

* Add tests for fuel param types
  • Loading branch information
DZakh authored Sep 17, 2024
1 parent a4602ab commit 5b9be2c
Show file tree
Hide file tree
Showing 23 changed files with 3,976 additions and 203 deletions.
2 changes: 1 addition & 1 deletion codegenerator/cli/src/fuel/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl FuelAbi {
"b256" | "address" => String.to_ok_expr(),
"str" => String.to_ok_expr(),
type_field if type_field.starts_with("str[") => String.to_ok_expr(),
"struct Vec" => Array(Box::new(GenericParam(
"struct std::vec::Vec" => Array(Box::new(GenericParam(
get_first_type_param()
.context("Failed getting param for struct Vec")?,
)))
Expand Down
2 changes: 1 addition & 1 deletion codegenerator/cli/src/rescript_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl RescriptTypeDecl {
let params = self
.parameters
.iter()
.map(|param| format!("_{}Schema", param))
.map(|param| format!("_{param}Schema: S.t<'{param}>"))
.collect::<Vec<String>>()
.join(", ");
let type_name = format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"rescript": "11.1.3",
"rescript-envsafe": "4.2.0",
"rescript-express": "0.4.1",
"rescript-schema": "8.0.0",
"rescript-schema": "8.2.0",
"root": "{{relative_path_to_root_from_generated}}",
"viem": "2.21.0",
"yargs": "17.7.2"
Expand Down
25 changes: 9 additions & 16 deletions codegenerator/cli/templates/dynamic/codegen/src/db/Enums.res.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,11 @@ module ContractType = {
| @as("{{contract.name.capitalized}}") {{contract.name.capitalized}}
{{/each}}

let schema =
{{#if codegen_contracts.1}}
S.union([
let schema = S.enum([
{{#each codegen_contracts as | contract |}}
S.literal({{contract.name.capitalized}}),
{{contract.name.capitalized}},
{{/each}}
])
{{else}}
{{#each codegen_contracts as | contract |}}
S.literal({{contract.name.capitalized}})
{{/each}}
{{/if}}
])

let name = "CONTRACT_TYPE"
let variants = [
Expand All @@ -50,10 +43,10 @@ module EntityType = {
| @as("{{entity.name.capitalized}}") {{entity.name.capitalized}}
{{/each}}

let schema = S.union([
{{#each entities as | entity |}}
S.literal({{entity.name.capitalized}}),
{{/each}}
let schema = S.enum([
{{#each entities as | entity |}}
{{entity.name.capitalized}},
{{/each}}
])

let name = "ENTITY_TYPE"
Expand All @@ -76,9 +69,9 @@ module {{enum.name.capitalized}} = {


let default = {{enum.params.[0].capitalized}}
let schema: S.t<t> = S.union([
let schema: S.t<t> = S.enum([
{{#each enum.params as | param | }}
S.literal({{param.capitalized}}),
{{param.capitalized}},
{{/each}}
])

Expand Down
26 changes: 3 additions & 23 deletions codegenerator/cli/templates/static/codegen/src/Env.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,7 @@ Dotenv.initialize()
let getLogLevelConfig = (name, ~default): Pino.logLevel =>
envSafe->EnvSafe.get(
name,
S.union([
S.literal(#trace),
S.literal(#debug),
S.literal(#info),
S.literal(#warn),
S.literal(#error),
S.literal(#fatal),
S.literal(#udebug),
S.literal(#uinfo),
S.literal(#uwarn),
S.literal(#uerror),
]),
S.enum([#trace, #debug, #info, #warn, #error, #fatal, #udebug, #uinfo, #uwarn, #uerror]),
~fallback=default,
)
)
Expand Down Expand Up @@ -48,15 +37,7 @@ type logStrategyType =
let logStrategy =
envSafe->EnvSafe.get(
"LOG_STRATEGY",
S.union([
S.literal(EcsFile),
S.literal(EcsConsole),
S.literal(EcsConsoleMultistream),
S.literal(FileOnly),
S.literal(ConsoleRaw),
S.literal(ConsolePretty),
S.literal(Both),
]),
S.enum([EcsFile, EcsConsole, EcsConsoleMultistream, FileOnly, ConsoleRaw, ConsolePretty, Both]),
~fallback=ConsolePretty,
)

Expand Down Expand Up @@ -112,8 +93,7 @@ module Configurable = {
envSafe->EnvSafe.get("ENVIO_RPC_BACKOFF_MULTIPLICATIVE", S.option(S.float))
let accelerationAdditive =
envSafe->EnvSafe.get("ENVIO_RPC_ACCELERATION_ADDITIVE", S.option(S.int))
let intervalCeiling =
envSafe->EnvSafe.get("ENVIO_RPC_INTERVAL_CEILING", S.option(S.int))
let intervalCeiling = envSafe->EnvSafe.get("ENVIO_RPC_INTERVAL_CEILING", S.option(S.int))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ type sslOptions =
| @as("prefer") Prefer
| @as("verify-full") VerifyFull

let sslOptionsSchema: S.schema<sslOptions> = S.union([
S.literal(Bool(true)),
S.literal(Bool(false)),
S.literal(Require),
S.literal(Allow),
S.literal(Prefer),
S.literal(VerifyFull),
let sslOptionsSchema: S.schema<sslOptions> = S.enum([
Bool(true),
Bool(false),
Require,
Allow,
Prefer,
VerifyFull,
//No schema created for tlsConnectOptions obj
])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ module QueryTypes = {
| @as("uncles") Uncles
| @as("base_fee_per_gas") BaseFeePerGas

let blockFieldOptionsSchema = S.union([
S.literal(Number),
S.literal(Hash),
S.literal(ParentHash),
S.literal(Nonce),
S.literal(Sha3Uncles),
S.literal(LogsBloom),
S.literal(TransactionsRoot),
S.literal(StateRoot),
S.literal(ReceiptsRoot),
S.literal(Miner),
S.literal(Difficulty),
S.literal(TotalDifficulty),
S.literal(ExtraData),
S.literal(Size),
S.literal(GasLimit),
S.literal(GasUsed),
S.literal(Timestamp),
S.literal(Uncles),
S.literal(BaseFeePerGas),
let blockFieldOptionsSchema = S.enum([
Number,
Hash,
ParentHash,
Nonce,
Sha3Uncles,
LogsBloom,
TransactionsRoot,
StateRoot,
ReceiptsRoot,
Miner,
Difficulty,
TotalDifficulty,
ExtraData,
Size,
GasLimit,
GasUsed,
Timestamp,
Uncles,
BaseFeePerGas,
])

type blockFieldSelection = array<blockFieldOptions>
Expand Down Expand Up @@ -76,33 +76,33 @@ module QueryTypes = {
| @as("status") Status
| @as("sighash") Sighash

let transactionFieldOptionsSchema = S.union([
S.literal(BlockHash),
S.literal(BlockNumber),
S.literal(From),
S.literal(Gas),
S.literal(GasPrice),
S.literal(Hash),
S.literal(Input),
S.literal(Nonce),
S.literal(To),
S.literal(TransactionIndex),
S.literal(Value),
S.literal(V),
S.literal(R),
S.literal(S),
S.literal(MaxPriorityFeePerGas),
S.literal(MaxFeePerGas),
S.literal(ChainId),
S.literal(CumulativeGasUsed),
S.literal(EffectiveGasPrice),
S.literal(GasUsed),
S.literal(ContractAddress),
S.literal(LogsBloom),
S.literal(Type),
S.literal(Root),
S.literal(Status),
S.literal(Sighash),
let transactionFieldOptionsSchema = S.enum([
BlockHash,
BlockNumber,
From,
Gas,
GasPrice,
Hash,
Input,
Nonce,
To,
TransactionIndex,
Value,
V,
R,
S,
MaxPriorityFeePerGas,
MaxFeePerGas,
ChainId,
CumulativeGasUsed,
EffectiveGasPrice,
GasUsed,
ContractAddress,
LogsBloom,
Type,
Root,
Status,
Sighash,
])

type transactionFieldSelection = array<transactionFieldOptions>
Expand All @@ -123,19 +123,19 @@ module QueryTypes = {
| @as("topic2") Topic2
| @as("topic3") Topic3

let logFieldOptionsSchema = S.union([
S.literal(Removed),
S.literal(LogIndex),
S.literal(TransactionIndex),
S.literal(TransactionHash),
S.literal(BlockHash),
S.literal(BlockNumber),
S.literal(Address),
S.literal(Data),
S.literal(Topic0),
S.literal(Topic1),
S.literal(Topic2),
S.literal(Topic3),
let logFieldOptionsSchema = S.enum([
Removed,
LogIndex,
TransactionIndex,
TransactionHash,
BlockHash,
BlockNumber,
Address,
Data,
Topic0,
Topic1,
Topic2,
Topic3,
])

type logFieldSelection = array<logFieldOptions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module InitApi = {
let bodySchema = S.object(s => {
envioVersion: s.field("envioVersion", S.option(S.string)),
envioApiToken: s.field("envioApiToken", S.option(S.string)),
ecosystem: s.field("ecosystem", S.union([S.literal(Evm), S.literal(Fuel)])),
ecosystem: s.field("ecosystem", S.enum([Evm, Fuel])),
hyperSyncNetworks: s.field("hyperSyncNetworks", S.array(S.int)),
rpcNetworks: s.field("rpcNetworks", S.array(S.int)),
})
Expand Down Expand Up @@ -70,10 +70,7 @@ module InitApi = {
}

let messageSchema = S.object(s => {
color: s.field(
"color",
S.union([Primary, Secondary, Info, Danger, Success, White, Gray]->Belt.Array.map(S.literal)),
),
color: s.field("color", S.enum([Primary, Secondary, Info, Danger, Success, White, Gray])),
content: s.field("content", S.string),
})

Expand Down
2 changes: 1 addition & 1 deletion scenarios/erc20_multichain_factory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"helpers": "../helpers",
"mocha": "10.2.0",
"rescript": "11.1.3",
"rescript-schema": "8.0.0"
"rescript-schema": "8.2.0"
},
"optionalDependencies": {
"generated": "./generated"
Expand Down
24 changes: 12 additions & 12 deletions scenarios/erc20_multichain_factory/pnpm-lock.yaml

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

Loading

0 comments on commit 5b9be2c

Please sign in to comment.