ckb-std icon indicating copy to clipboard operation
ckb-std copied to clipboard

[Question] How to extract `accumulated_rate`?

Open phroi opened this issue 10 months ago • 0 comments

Hey Cryptape, iCKB here 👋 I was updating iCKB Logic implementation to use ckb-std 0.15.3 and I stumbled upon an apparent issue:

  • I'm unable to unpack the result of load_header(index, source)?.raw().dao()
  • The only implementation to obtain accumulated_rate that works is:
    let d = load_header(index, source)?.raw().dao();
    let accumulated_rate = u64::from_le_bytes([
        u8::from(d.nth8()),
        u8::from(d.nth9()),
        u8::from(d.nth10()),
        u8::from(d.nth11()),
        u8::from(d.nth12()),
        u8::from(d.nth13()),
        u8::from(d.nth14()),
        u8::from(d.nth15()),
    ]);

So my questions are:

  1. What's the best way to extract accumulated_rate?
  2. Can you double check that the unpack of Byte32 is working as expected?

As when I try to unpack dao_data I get the following error:

Compiling ickb_logic v1.2.0 (/home/user/ickb/ickb_logic/contracts/ickb_logic)
error[E0599]: no method named `unpack` found for struct `Byte32` in the current scope
  --> contracts/ickb_logic/src/utils.rs:57:14
   |
57 |     dao_data.unpack();
   |              ^^^^^^ method not found in `Byte32`

warning: unused import: `ckb_types::prelude::Unpack`
 --> contracts/ickb_logic/src/utils.rs:5:5
  |
5 |     ckb_types::prelude::Unpack,
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Keep up the Great Work, Phroi

phroi avatar Apr 16 '24 11:04 phroi