Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Jan 28, 2025
1 parent 6ced289 commit 4fe0bed
Showing 1 changed file with 74 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,16 @@ pub(crate) fn static_json_rpc_url() -> Url {

#[cfg(test)]
mod test {
use std::convert::TryFrom;
use std::{convert::TryFrom, str::FromStr};

use hex::ToHex;
use hyper::HeaderMap;
use monero::{
blockdata::transaction::{ExtraField, RawExtraField},
consensus::deserialize,
util::ringct::Key,
Block,
Hash,
};
use monero::{blockdata::transaction::{
ExtraField,
RawExtraField,
SubField::{Nonce, TxPublicKey},
}, consensus::deserialize, util::ringct::Key, Block, BlockHeader, Hash, PublicKey, Transaction, TransactionPrefix, VarInt};
use monero::consensus::serialize;
use serde_json::{json, to_string_pretty};
use url::Url;

Expand Down Expand Up @@ -411,16 +411,35 @@ mod test {
252, 52, 69, 167, 73, 197, 39, 107, 98,
]);
println!("prev_id: {}", hex::encode(prev_id));
let prev_id = Hash::from_str("efc7fe28768c12d3ffea676ea9c92a56f14824b06d2fc17afce15e627489ac7b").unwrap();

let key = Key::from([
35, 223, 82, 74, 242, 162, 239, 95, 135, 10, 219, 110, 28, 235, 3, 164, 117, 195, 159, 139, 158, 247, 106,
165, 11, 70, 221, 210, 161, 131, 73, 64,
]);
println!("key: {}", key);
let extra = RawExtraField([
1, 40, 57, 191, 161, 155, 117, 36, 236, 116, 136, 145, 119, 20, 194, 22, 202, 37, 75, 56, 237, 4, 36, 202,
101, 174, 130, 138, 124, 0, 106, 234, 241, 2, 8, 245, 49, 106, 127, 107, 153, 204, 166,
].to_vec());
println!("extra: {}", ExtraField::try_parse(&extra).unwrap());
let key = Key::from(
Hash::from_str("23df524af2a2ef5f870adb6e1ceb03a475c39f8b9ef76aa50b46ddd2a1834940")
.unwrap()
.to_bytes(),
);
println!("key: {}", key);

let extra = RawExtraField(
[
1, 40, 57, 191, 161, 155, 117, 36, 236, 116, 136, 145, 119, 20, 194, 22, 202, 37, 75, 56, 237, 4, 36,
202, 101, 174, 130, 138, 124, 0, 106, 234, 241, 2, 8, 245, 49, 106, 127, 107, 153, 204, 166,
]
.to_vec(),
);
println!("extra: {}", ExtraField::try_parse(&extra).unwrap());
let extra = RawExtraField::from(ExtraField(vec![
TxPublicKey(
PublicKey::from_str("2839bfa19b7524ec7488917714c216ca254b38ed0424ca65ae828a7c006aeaf1").unwrap(),
),
Nonce(hex::decode("08f5316a7f6b99cca6").unwrap()),
]));

let json = serde_json::json!({
"header": {
"major_version": 12,
Expand All @@ -434,21 +453,21 @@ mod test {
"version": 2,
"unlock_time": 558235,
"inputs": [
{
"Gen": {
"height": 558175
}
}
{
"Gen": {
"height": 558175
}
}
],
"outputs": [
{
"amount": 12520250477750i64,
"target": {
"ToKey": {
"key": key.key
{
"amount": 12520250477750i64,
"target": {
"ToKey": {
"key": key.key
}
}
}
}
}
],
"extra": extra.0
},
Expand All @@ -466,5 +485,35 @@ mod test {
},
"tx_hashes": []
});

let block = Block {
header: BlockHeader {
major_version: VarInt(12),
minor_version: VarInt(12),
timestamp: VarInt(1594797844),
prev_id,
nonce: 0,
},
miner_tx: Transaction {
prefix: TransactionPrefix {
version: VarInt(2),
unlock_time: VarInt(558235),
inputs: vec![monero::blockdata::transaction::TxIn::Gen {height: VarInt(558175)}],
outputs: vec![
monero::blockdata::transaction::TxOut {
amount: VarInt(12520250477750),
target: monero::blockdata::transaction::TxOutTarget::ToKey { key: key.key } ,
}
],
extra,
},
signatures: Default::default(),
rct_signatures: Default::default(),
},
tx_hashes: Default::default(),
};

let json_block = to_string_pretty(&block).unwrap();
println!("{}", json_block);
}
}

0 comments on commit 4fe0bed

Please sign in to comment.