Created
March 12, 2025 13:25
-
-
Save jmg-duarte/5c75bf0d7dc2d7af89694f80ea846fdf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{io::Cursor, str::FromStr}; | |
use cid::Cid; | |
use codec::{Decode, Encode, IoReader}; | |
use storagext::{ | |
runtime::runtime_types::pallet_market::pallet::DealProposal as RtDealProposal, | |
types::market::DealProposal, BlockNumber, Currency, | |
}; | |
use subxt::ext::sp_runtime::AccountId32; | |
fn main() { | |
let proposal = DealProposal { | |
piece_cid: Cid::from_str("bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi") | |
.unwrap(), | |
piece_size: 1073741824, | |
client: AccountId32::from_str("5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY").unwrap(), | |
provider: AccountId32::from_str("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty") | |
.unwrap(), | |
label: "My Storage Deal".to_string(), | |
start_block: 100000, | |
end_block: 200000, | |
storage_price_per_block: 10000000000, | |
provider_collateral: 50000000000, | |
state: storagext::runtime::runtime_types::pallet_market::pallet::DealState::Published, | |
}; | |
let rt_proposal: RtDealProposal<_, _, _> = proposal.into(); | |
let encoded = &rt_proposal.encode(); | |
println!("{}", hex::encode(encoded)); | |
let scale = "9001701220c3c4733ec8affd06cf9e9ff50ffc6bcd2ec85a6170004bb709669c31de94391a0000004000000000d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a483c4d792053746f72616765204465616ca086010000000000400d03000000000000e40b5402000000000000000000000000743ba40b000000000000000000000000"; | |
let bytes = hex::decode(&scale).unwrap(); | |
let bytes = Cursor::new(bytes); | |
let proposal: RtDealProposal< | |
subxt::ext::subxt_core::utils::AccountId32, | |
Currency, | |
BlockNumber, | |
> = RtDealProposal::decode(&mut IoReader(bytes)).unwrap(); | |
println!("{:?}", proposal); | |
assert_eq!(rt_proposal, proposal); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment