Commit 3eb9458
feat: expose offsets_with_data on configurables (#1685)
- Expose offsets_with_data on Configurables this allows for better DX
when interacting with the Standard SRC12 that requires configurable to
be provided as `Vec<(u64, Vec<u8>)>`.
Note: I have made `offsets_with_data` public and also implement `Into`.
I'm not sure what is the best solution here, so once reviewed it can be
decided how to procede.
Ex.:
/// Current way to implement:
```rs
// For this two info requires manual change or reading the JSON
const PROXY_ORACLE_ID_OFFSET: u64 = 38488;
const PROXY_OWNER_OFFSET: u64 = 38440;
pub fn build_trade_account_proxy_configurables(
oracle_id: ContractId,
owner: Identity,
) -> Vec<(u64, Vec<u8>)> {
let mut my_configurables: Vec<(u64, Vec<u8>)> = Vec::with_capacity(2);
my_configurables.push((PROXY_ORACLE_ID_OFFSET, oracle_id.to_vec()));
let mut owner_data: Vec<u8> = Vec::new();
owner_data.extend_from_slice(&[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8]); // State::Initialized
match owner {
Identity::Address(address) => {
owner_data.extend_from_slice(&[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8]); // Identity::Address
owner_data.extend_from_slice(&*address.to_vec());
}
Identity::ContractId(contract_id) => {
owner_data.extend_from_slice(&[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 1u8]); // Identity::ContractId
owner_data.extend_from_slice(&*contract_id.to_vec());
}
}
my_configurables.push((PROXY_OWNER_OFFSET, owner_data));
my_configurables
}
```
/// With the changes
```rs
pub fn build_trade_account_proxy_configurables(
oracle_id: ContractId,
owner: Identity,
) -> Vec<(u64, Vec<u8>)> {
TradingAccountProxyConfigurables::default()
.with_ORACLE_CONTRACT_ID(oracle_id)
.unwrap()
.with_INITIAL_OWNER(State::Initialized(owner))
.unwrap()
.into()
}
```
The standard implementation is defined as:
```sway
impl SRC12 for Contract {
#[storage(read, write)]
fn register_contract(
child_contract: ContractId,
configurables: Option<Vec<(u64, Vec<u8>)>>,
) -> Result<BytecodeRoot, str> {
```
---------
Co-authored-by: green <[email protected]>1 parent d0a0ce7 commit 3eb9458
File tree
6 files changed
+81
-28
lines changed- docs/src/codec
- packages
- fuels-code-gen/src/program_bindings/abigen
- fuels-core/src
- fuels-programs/src
- fuels-test-helpers/src
- fuels/src
6 files changed
+81
-28
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
| 15 | + | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
Lines changed: 10 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
93 | 96 | | |
94 | 97 | | |
95 | 98 | | |
| |||
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
119 | 127 | | |
120 | 128 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | | - | |
| 20 | + | |
13 | 21 | | |
14 | 22 | | |
15 | 23 | | |
16 | | - | |
| 24 | + | |
17 | 25 | | |
18 | 26 | | |
19 | 27 | | |
20 | 28 | | |
21 | 29 | | |
22 | 30 | | |
23 | 31 | | |
24 | | - | |
| 32 | + | |
25 | 33 | | |
26 | | - | |
| 34 | + | |
27 | 35 | | |
28 | | - | |
| 36 | + | |
29 | 37 | | |
30 | 38 | | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | | - | |
| 42 | + | |
| 43 | + | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
| |||
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
51 | 63 | | |
52 | 64 | | |
53 | 65 | | |
54 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
55 | 73 | | |
56 | 74 | | |
57 | 75 | | |
58 | 76 | | |
59 | 77 | | |
60 | 78 | | |
61 | | - | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
62 | 83 | | |
63 | 84 | | |
64 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
65 | 89 | | |
66 | 90 | | |
67 | 91 | | |
| |||
70 | 94 | | |
71 | 95 | | |
72 | 96 | | |
73 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
74 | 101 | | |
75 | 102 | | |
76 | | - | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
77 | 107 | | |
78 | 108 | | |
79 | 109 | | |
| |||
82 | 112 | | |
83 | 113 | | |
84 | 114 | | |
85 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
86 | 119 | | |
87 | 120 | | |
88 | 121 | | |
| |||
94 | 127 | | |
95 | 128 | | |
96 | 129 | | |
97 | | - | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
98 | 134 | | |
99 | 135 | | |
100 | 136 | | |
| |||
108 | 144 | | |
109 | 145 | | |
110 | 146 | | |
111 | | - | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
112 | 151 | | |
113 | 152 | | |
114 | 153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
276 | 279 | | |
277 | 280 | | |
278 | 281 | | |
| |||
285 | 288 | | |
286 | 289 | | |
287 | 290 | | |
288 | | - | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
289 | 295 | | |
290 | 296 | | |
291 | 297 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
6 | 4 | | |
7 | 5 | | |
| 6 | + | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
90 | 89 | | |
91 | 90 | | |
92 | 91 | | |
93 | | - | |
| 92 | + | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
0 commit comments