darwinia-network / darwinia-messages-sol

Darwinia cross-chain messages gateway and protocol for EVM developers 💌
MIT License
29 stars 8 forks source link

Commitment Codec #136

Closed AurevoirXavier closed 2 years ago

AurevoirXavier commented 2 years ago
use beefy_primitives::VersionedCommitment;
use parity_scale_codec::{Decode, Encode};

type C = VersionedCommitment<u32>;

fn main() {
    let raw_hex = "0x01046462809395314ca21ea6504bdc977e842537a7cb605c6693ee7cebbbed581430446d59f90800000000000000000000048001000000043d31122e484b913210d781135062f842ba2f9b285d0fc18dd00c1f8e8219c7321e4fb39bf41c046c42617e72fbf1af7fe3730c24d676803549e0dffcc18c418201";
    let raw_bytes = array_bytes::hex2bytes_unchecked(raw_hex);
    let c = C::decode(&mut &*raw_bytes).unwrap();

    dbg!(&c);

    let raw_bytes = c.encode();
    let raw_hex = array_bytes::bytes2hex("0x", raw_bytes);

    dbg!(raw_hex);
}
[src/main.rs:11] &c = V1(
    SignedCommitment {
        commitment: Commitment {
            payload: Payload(
                [
                    (
                        [
                            100,
                            98,
                        ],
                        [
                            147,
                            149,
                            49,
                            76,
                            162,
                            30,
                            166,
                            80,
                            75,
                            220,
                            151,
                            126,
                            132,
                            37,
                            55,
                            167,
                            203,
                            96,
                            92,
                            102,
                            147,
                            238,
                            124,
                            235,
                            187,
                            237,
                            88,
                            20,
                            48,
                            68,
                            109,
                            89,
                        ],
                    ),
                ],
            ),
            block_number: 2297,
            validator_set_id: 0,
        },
        signatures: [
            Some(
                Signature(
                    3d31122e484b913210d781135062f842ba2f9b285d0fc18dd00c1f8e8219c7321e4fb39bf41c046c42617e72fbf1af7fe3730c24d676803549e0dffcc18c418201,
                ),
            ),
        ],
    },
)
[src/main.rs:16] raw_hex = "0x01046462809395314ca21ea6504bdc977e842537a7cb605c6693ee7cebbbed581430446d59f90800000000000000000000048001000000043d31122e484b913210d781135062f842ba2f9b285d0fc18dd00c1f8e8219c7321e4fb39bf41c046c42617e72fbf1af7fe3730c24d676803549e0dffcc18c418201"
AurevoirXavier commented 2 years ago

https://github.com/darwinia-network/darwinia-bridge-sol/blob/6d537de974f35b6b704b6ce8d6e9bc5fba2ed5fd/contracts/bridge/e2e/helper/test.js#L35

Looks like the JS library could not handle the type Vec<Option<T>>.

hujw77 commented 2 years ago

Polkdot.js issue.