Skip to content

Commit 763b59a

Browse files
Change nulls to undefined in Rust and apply format lints
1 parent 1b0f732 commit 763b59a

File tree

4 files changed

+43
-25
lines changed

4 files changed

+43
-25
lines changed

sdk/tests/network-client.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ describe('NodeConnection', () => {
341341
// Ensure the object summary returns the correct general transaction metadata.
342342
expect(summary.type).equals(transaction.transactionType());
343343
expect(summary.feeAmount).equals(transaction.feeAmount());
344-
expect(summary.execution).equals(null);
344+
expect(summary.execution).equals(undefined);
345345
expect(summary.id).equals(transaction.id());
346346
expect(summary.feeAmount).equals(transaction.feeAmount());
347347
expect(summary.baseFee).equals(transaction.baseFeeAmount());

wasm/src/ledger/transaction.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,21 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with the Aleo SDK library. If not, see <https://www.gnu.org/licenses/>.
1616

17-
use crate::{input_to_js_value, object, output_to_js_value, types::native::{FromBytes, ToBytes, TransactionNative, U64Native}, Address, Field, Group, RecordCiphertext, RecordPlaintext, Signature, Transition, VerifyingKey, ViewKey};
17+
use crate::{
18+
input_to_js_value,
19+
object,
20+
output_to_js_value,
21+
types::native::{FromBytes, ToBytes, TransactionNative, U64Native},
22+
Address,
23+
Field,
24+
Group,
25+
RecordCiphertext,
26+
RecordPlaintext,
27+
Signature,
28+
Transition,
29+
VerifyingKey,
30+
ViewKey,
31+
};
1832

1933
use js_sys::{Array, Object, Reflect, Uint8Array};
2034
use std::{ops::Deref, str::FromStr};
@@ -213,7 +227,7 @@ impl Transaction {
213227
};
214228
JsValue::from(execution_object)
215229
} else {
216-
JsValue::NULL
230+
JsValue::UNDEFINED
217231
};
218232

219233
// If the transaction is a deployment, summarize the deployment.
@@ -229,15 +243,14 @@ impl Transaction {
229243
}
230244
}).collect::<Array>();
231245

232-
233246
// Create the deployment object.
234247
JsValue::from(object! {
235248
"edition" : deployment.edition(),
236249
"program" : deployment.program_id().to_string(),
237250
"functions" : functions,
238251
})
239252
} else {
240-
JsValue::NULL
253+
JsValue::UNDEFINED
241254
};
242255

243256
let owner = self.0.owner().map(|owner| {
@@ -247,7 +260,7 @@ impl Transaction {
247260
};
248261
JsValue::from(owner)
249262
})
250-
.unwrap_or_else(|| JsValue::NULL);
263+
.unwrap_or_else(|| JsValue::UNDEFINED);
251264

252265
// Extract the fee execution.
253266
let fee = match &self.0 {
@@ -258,12 +271,9 @@ impl Transaction {
258271

259272
let fee_execution = if let Some(fee) = fee {
260273
// Collect the inputs and outputs.
261-
let inputs = fee.inputs().iter().map(|input| {
262-
input_to_js_value(input, convert_to_js)
263-
}).collect::<Array>();
264-
let outputs = fee.outputs().iter().map(|output| {
265-
output_to_js_value(output, convert_to_js)
266-
}).collect::<Array>();
274+
let inputs = fee.inputs().iter().map(|input| input_to_js_value(input, convert_to_js)).collect::<Array>();
275+
let outputs =
276+
fee.outputs().iter().map(|output| output_to_js_value(output, convert_to_js)).collect::<Array>();
267277
let fee_transition = object! {
268278
"program" : fee.program_id().to_string(),
269279
"function" : fee.function_name().to_string(),
@@ -281,7 +291,7 @@ impl Transaction {
281291
};
282292
JsValue::from(execution_object)
283293
} else {
284-
JsValue::NULL
294+
JsValue::UNDEFINED
285295
};
286296

287297
object! {
@@ -458,10 +468,14 @@ mod tests {
458468
let execution = Object::from(Reflect::get(&summary, &JsValue::from_str("execution")).unwrap());
459469
let transitions = Array::from(&Reflect::get(&execution, &JsValue::from_str("transitions")).unwrap()).to_vec();
460470
assert_eq!(transitions.len(), 2);
461-
let global_state_root = Reflect::get(&execution, &JsValue::from_str("global_state_root")).unwrap().as_string().unwrap();
471+
let global_state_root =
472+
Reflect::get(&execution, &JsValue::from_str("global_state_root")).unwrap().as_string().unwrap();
462473
let proof = Reflect::get(&execution, &JsValue::from_str("proof")).unwrap().as_string().unwrap();
463474
assert_eq!(&global_state_root, "sr1cxx6uf72kla7hzu65m394fljpup39h3efe97xsn2wm2gl9apjgyqdr94ud");
464-
assert_eq!(&proof, "proof1qyqsqqqqqqqqqqqpqqqqqqqqqqqvs2nmr0pnyufteq8wtf080x3vwfh5yk08d6pjmedl8j7gx6a42das2ul7rm9x6wn5tvars43nudvqq9gshva80utleuytjesa4vmkq4cv6kfcm6axn2pwf7klzk402gf9qn5t0ssz3mut0ycjcjwss4e76qrh46q8r8calfmrwmpmwj2j063rsgtvq4v85v8gzlyyy233f90pztncnx9pr65l28vuqwx86n0p2xqws3lw0a2qs4smanr5eq78rgn2t2vtvnfu07589676v86kjxdfc6nqdvmghjvc25zzh7qwj2jxmk5qtu5ecxd8mpx00mjs4q2sen68w57zk6c3e7xnm7jeelrqhuexaae9n8v9ddagrl27wwn8zg8vwv9srrar48d0aqslsmzt6lqnxq2mwn0y89zxtrsfs8uzphrc3geu9y5pn2m90k45s5cqt4ypw8rqea53qprslzcs0xpuhc6gc59lfxk0fz49wj70pxe4wczpnxcendf6f7ep49svrsamw2nn39y02dt3l85ztqr09hcxd6h9382cq2s3j890g6ezu2lktszy278dxhuxj47qmmjs2m2p78ud9s3m7pkrusrqwj65f6qv4h0spx0jsrs0vcyapz868egt4g6jf9zwmdkfn5d4966234td44gzcvzwghl2tcxxpl0vt70366upqd7se7pf8vmlvujalgwglgzu2tnrp474nmuvewflrd6eg8j6usg5c6l5vydrkjav4lqx8n4d83nre9qex57ut3nunlyccedx3npxuqzu4fk6293yxxd0sd05jrtxkjpckqrvaaxnng22j9dxnlrvxm24ql5880tdnd8mwsmhz9hf4tnwlrl65xu2x9tuqz5c4nsha95hqlksj3mapzmc5672md4hckakxfpt28znt0st8p3xwt05a3usl3remvc9e5ng8quakjgax4aquczfqvdxzwstm8et5tgdptkt84wnklwn5c8cy93ezx7rh4jve5dn2t8zcn32vph0d8sx583j6uqz6sg8mjs6upgdsf47d6ageygydpve89p3tsshx5vt98jzet9hnkfacky5hpxgqlgnm0dvchgylg3prq05gq7kzdu8narls66gg7nxml0hzqsrh0lqez38m40dzt9zzg985frap8m43ehfk5z9lpsazc7jx0fyp2qcrncdqvqqqqqqqqqqqkfq8j9ez9zl7gycv3wzsjez8amk3lkrptn62v0xp805dmckhl38k3hn0vc5v54wre6m0n8mcvz3qyq2fchjxd29juplmjywlrfz83zkq2ev6mxryx5dz43tcwneamnpa5m6ezycmqed4dsfrm342e3693qqq8gj3sheypdtugcnxfuvw5pqn5glpxc8hy8efn8z366lm6l46luqpfn0c6cv8jnfkqg8x0djhm97ex4w43ljp2q3p48puy5qg7plrl3082j669dptpvp62h8wrmvl4ggsyqqxqxmd4");
475+
assert_eq!(
476+
&proof,
477+
"proof1qyqsqqqqqqqqqqqpqqqqqqqqqqqvs2nmr0pnyufteq8wtf080x3vwfh5yk08d6pjmedl8j7gx6a42das2ul7rm9x6wn5tvars43nudvqq9gshva80utleuytjesa4vmkq4cv6kfcm6axn2pwf7klzk402gf9qn5t0ssz3mut0ycjcjwss4e76qrh46q8r8calfmrwmpmwj2j063rsgtvq4v85v8gzlyyy233f90pztncnx9pr65l28vuqwx86n0p2xqws3lw0a2qs4smanr5eq78rgn2t2vtvnfu07589676v86kjxdfc6nqdvmghjvc25zzh7qwj2jxmk5qtu5ecxd8mpx00mjs4q2sen68w57zk6c3e7xnm7jeelrqhuexaae9n8v9ddagrl27wwn8zg8vwv9srrar48d0aqslsmzt6lqnxq2mwn0y89zxtrsfs8uzphrc3geu9y5pn2m90k45s5cqt4ypw8rqea53qprslzcs0xpuhc6gc59lfxk0fz49wj70pxe4wczpnxcendf6f7ep49svrsamw2nn39y02dt3l85ztqr09hcxd6h9382cq2s3j890g6ezu2lktszy278dxhuxj47qmmjs2m2p78ud9s3m7pkrusrqwj65f6qv4h0spx0jsrs0vcyapz868egt4g6jf9zwmdkfn5d4966234td44gzcvzwghl2tcxxpl0vt70366upqd7se7pf8vmlvujalgwglgzu2tnrp474nmuvewflrd6eg8j6usg5c6l5vydrkjav4lqx8n4d83nre9qex57ut3nunlyccedx3npxuqzu4fk6293yxxd0sd05jrtxkjpckqrvaaxnng22j9dxnlrvxm24ql5880tdnd8mwsmhz9hf4tnwlrl65xu2x9tuqz5c4nsha95hqlksj3mapzmc5672md4hckakxfpt28znt0st8p3xwt05a3usl3remvc9e5ng8quakjgax4aquczfqvdxzwstm8et5tgdptkt84wnklwn5c8cy93ezx7rh4jve5dn2t8zcn32vph0d8sx583j6uqz6sg8mjs6upgdsf47d6ageygydpve89p3tsshx5vt98jzet9hnkfacky5hpxgqlgnm0dvchgylg3prq05gq7kzdu8narls66gg7nxml0hzqsrh0lqez38m40dzt9zzg985frap8m43ehfk5z9lpsazc7jx0fyp2qcrncdqvqqqqqqqqqqqkfq8j9ez9zl7gycv3wzsjez8amk3lkrptn62v0xp805dmckhl38k3hn0vc5v54wre6m0n8mcvz3qyq2fchjxd29juplmjywlrfz83zkq2ev6mxryx5dz43tcwneamnpa5m6ezycmqed4dsfrm342e3693qqq8gj3sheypdtugcnxfuvw5pqn5glpxc8hy8efn8z366lm6l46luqpfn0c6cv8jnfkqg8x0djhm97ex4w43ljp2q3p48puy5qg7plrl3082j669dptpvp62h8wrmvl4ggsyqqxqxmd4"
478+
);
465479

466480
// Check the transfer_public transition.
467481
let transition = Object::from(transitions[0].clone());
@@ -586,7 +600,8 @@ mod tests {
586600
// Check the fee execution.
587601
let fee_execution = Object::from(Reflect::get(&summary, &JsValue::from_str("fee")).unwrap());
588602
let fee_transition = Object::from(Reflect::get(&fee_execution, &JsValue::from_str("transition")).unwrap());
589-
let fee_stateroot = Reflect::get(&fee_execution, &JsValue::from_str("global_state_root")).unwrap().as_string().unwrap();
603+
let fee_stateroot =
604+
Reflect::get(&fee_execution, &JsValue::from_str("global_state_root")).unwrap().as_string().unwrap();
590605
assert_eq!(&fee_stateroot, "sr1cxx6uf72kla7hzu65m394fljpup39h3efe97xsn2wm2gl9apjgyqdr94ud");
591606
assert_eq!(
592607
Reflect::get(&fee_transition, &JsValue::from_str("program")).unwrap().as_string().unwrap(),

wasm/src/programs/data/helpers/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn input_to_js_value(input: &InputNative, convert_to_js: bool) -> JsValue {
2525
let value = if let Some(plaintext) = plaintext {
2626
if convert_to_js { plaintext_to_js_value(plaintext) } else { JsValue::from(Plaintext::from(plaintext)) }
2727
} else {
28-
JsValue::NULL
28+
JsValue::UNDEFINED
2929
};
3030
let constant_input = object! {
3131
"type": "constant",
@@ -38,7 +38,7 @@ pub fn input_to_js_value(input: &InputNative, convert_to_js: bool) -> JsValue {
3838
let value = if let Some(plaintext) = plaintext {
3939
if convert_to_js { plaintext_to_js_value(plaintext) } else { JsValue::from(Plaintext::from(plaintext)) }
4040
} else {
41-
JsValue::NULL
41+
JsValue::UNDEFINED
4242
};
4343
let public_input = object! {
4444
"type" : "public",
@@ -55,7 +55,7 @@ pub fn input_to_js_value(input: &InputNative, convert_to_js: bool) -> JsValue {
5555
JsValue::from(Ciphertext::from(ciphertext))
5656
}
5757
} else {
58-
JsValue::NULL
58+
JsValue::UNDEFINED
5959
};
6060
let private_input = object! {
6161
"type" : "private",

wasm/src/programs/data/helpers/output.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn output_to_js_value(output: &OutputNative, convert_to_js: bool) -> JsValue
3434
let value = if let Some(plaintext) = plaintext {
3535
if convert_to_js { plaintext_to_js_value(plaintext) } else { JsValue::from(Plaintext::from(plaintext)) }
3636
} else {
37-
JsValue::NULL
37+
JsValue::UNDEFINED
3838
};
3939
let constant = object! {
4040
"type" : "constant",
@@ -47,7 +47,7 @@ pub fn output_to_js_value(output: &OutputNative, convert_to_js: bool) -> JsValue
4747
let value = if let Some(plaintext) = plaintext {
4848
if convert_to_js { plaintext_to_js_value(plaintext) } else { JsValue::from(Plaintext::from(plaintext)) }
4949
} else {
50-
JsValue::NULL
50+
JsValue::UNDEFINED
5151
};
5252
let public_output = object! {
5353
"type" : "constant",
@@ -64,7 +64,7 @@ pub fn output_to_js_value(output: &OutputNative, convert_to_js: bool) -> JsValue
6464
JsValue::from(Ciphertext::from(ciphertext))
6565
}
6666
} else {
67-
JsValue::NULL
67+
JsValue::UNDEFINED
6868
};
6969
let private_output = object! {
7070
"type" : "constant",
@@ -81,7 +81,7 @@ pub fn output_to_js_value(output: &OutputNative, convert_to_js: bool) -> JsValue
8181
JsValue::from(RecordCiphertext::from(record_ciphertext))
8282
}
8383
} else {
84-
JsValue::NULL
84+
JsValue::UNDEFINED
8585
};
8686
let record = object! {
8787
"type": "record",
@@ -99,8 +99,11 @@ pub fn output_to_js_value(output: &OutputNative, convert_to_js: bool) -> JsValue
9999
JsValue::from(external_record_object)
100100
}
101101
OutputNative::Future(id, future) => {
102-
let value =
103-
if let Some(future) = future { future_to_js_value(future, convert_to_js, id) } else { JsValue::NULL };
102+
let value = if let Some(future) = future {
103+
future_to_js_value(future, convert_to_js, id)
104+
} else {
105+
JsValue::UNDEFINED
106+
};
104107
JsValue::from(&value)
105108
}
106109
};

0 commit comments

Comments
 (0)