Skip to content

Commit 872b76a

Browse files
committed
runtime/wasm: Impl and use From<Option<AscPtr<C>>> for AscPtr<C>
1 parent bea4c3f commit 872b76a

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

runtime/wasm/src/asc_abi/asc_ptr.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ impl<C: AscType> AscPtr<C> {
7474
}
7575
}
7676

77+
impl<C: AscType> From<Option<AscPtr<C>>> for AscPtr<C> {
78+
fn from(option: Option<AscPtr<C>>) -> Self {
79+
match option {
80+
Some(ptr) => ptr,
81+
None => AscPtr::null(),
82+
}
83+
}
84+
}
85+
7786
impl<C> From<u32> for AscPtr<C> {
7887
fn from(ptr: u32) -> Self {
7988
AscPtr(ptr, PhantomData)

runtime/wasm/src/to_from/external.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl ToAscObj<AscEthereumBlock> for EthereumBlockData {
320320
size: self
321321
.size
322322
.map(|size| heap.asc_new(&BigInt::from_unsigned_u256(&size)))
323-
.unwrap_or_else(|| AscPtr::null()),
323+
.into(),
324324
}
325325
}
326326
}
@@ -344,7 +344,7 @@ impl ToAscObj<AscFullEthereumBlock> for FullEthereumBlockData {
344344
size: self
345345
.size
346346
.map(|size| heap.asc_new(&BigInt::from_unsigned_u256(&size)))
347-
.unwrap_or_else(|| AscPtr::null()),
347+
.into(),
348348
transactions: heap.asc_new(self.transactions.as_slice()),
349349
}
350350
}
@@ -369,7 +369,7 @@ impl ToAscObj<AscFullEthereumBlockWithReceipts> for FullEthereumBlockDataWithRec
369369
size: self
370370
.size
371371
.map(|size| heap.asc_new(&BigInt::from_unsigned_u256(&size)))
372-
.unwrap_or_else(|| AscPtr::null()),
372+
.into(),
373373
transaction_receipts: heap.asc_new(self.transaction_receipts.as_slice()),
374374
}
375375
}
@@ -386,26 +386,20 @@ impl ToAscObj<AscEthereumTransactionReceipt> for EthereumTransactionReceiptData
386386
gas_used: self
387387
.gas_used
388388
.map(|gas_used| heap.asc_new(&BigInt::from_unsigned_u256(&gas_used)))
389-
.unwrap_or_else(|| AscPtr::null()),
389+
.into(),
390390
contract_address: self
391391
.contract_address
392392
.map(|contract_address| heap.asc_new(&contract_address))
393-
.unwrap_or_else(|| AscPtr::null()),
393+
.into(),
394394
status: self
395395
.status
396396
.map(|status| heap.asc_new(&BigInt::from(status)))
397-
.unwrap_or_else(|| AscPtr::null()),
398-
root: self
399-
.root
400-
.map(|root| heap.asc_new(&root))
401-
.unwrap_or_else(|| AscPtr::null()),
397+
.into(),
398+
root: self.root.map(|root| heap.asc_new(&root)).into(),
402399

403400
// // from txs
404401
from: heap.asc_new(&self.from),
405-
to: self
406-
.to
407-
.map(|to| heap.asc_new(&to))
408-
.unwrap_or_else(|| AscPtr::null()),
402+
to: self.to.map(|to| heap.asc_new(&to)).into(),
409403
value: heap.asc_new(&BigInt::from_unsigned_u256(&self.value)),
410404
gas_price: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_price)),
411405
gas: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas)),
@@ -420,10 +414,7 @@ impl ToAscObj<AscEthereumTransaction> for EthereumTransactionData {
420414
hash: heap.asc_new(&self.hash),
421415
index: heap.asc_new(&BigInt::from(self.index)),
422416
from: heap.asc_new(&self.from),
423-
to: self
424-
.to
425-
.map(|to| heap.asc_new(&to))
426-
.unwrap_or_else(|| AscPtr::null()),
417+
to: self.to.map(|to| heap.asc_new(&to)).into(),
427418
value: heap.asc_new(&BigInt::from_unsigned_u256(&self.value)),
428419
gas_used: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_used)),
429420
gas_price: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_price)),
@@ -437,10 +428,7 @@ impl ToAscObj<AscEthereumTransaction_0_0_2> for EthereumTransactionData {
437428
hash: heap.asc_new(&self.hash),
438429
index: heap.asc_new(&BigInt::from(self.index)),
439430
from: heap.asc_new(&self.from),
440-
to: self
441-
.to
442-
.map(|to| heap.asc_new(&to))
443-
.unwrap_or_else(|| AscPtr::null()),
431+
to: self.to.map(|to| heap.asc_new(&to)).into(),
444432
value: heap.asc_new(&BigInt::from_unsigned_u256(&self.value)),
445433
gas_used: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_used)),
446434
gas_price: heap.asc_new(&BigInt::from_unsigned_u256(&self.gas_price)),
@@ -463,7 +451,7 @@ where
463451
.log_type
464452
.clone()
465453
.map(|log_type| heap.asc_new(&log_type))
466-
.unwrap_or_else(|| AscPtr::null()),
454+
.into(),
467455
block: heap.asc_new(&self.block),
468456
transaction: heap.asc_new::<T, EthereumTransactionData>(&self.transaction),
469457
params: heap.asc_new(self.params.as_slice()),

0 commit comments

Comments
 (0)