Serialize memo as hex

This commit is contained in:
Hanh 2022-12-12 21:55:02 +08:00
parent c269eafe36
commit 2e9a0f5a62
1 changed files with 4 additions and 7 deletions

View File

@ -1,26 +1,23 @@
use crate::note_selection::types::{TransactionOutput, TransactionReport}; use crate::note_selection::types::{TransactionOutput, TransactionReport};
use crate::TransactionPlan; use crate::TransactionPlan;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use zcash_primitives::consensus::Network; use zcash_primitives::consensus::Network;
use zcash_primitives::memo::MemoBytes; use zcash_primitives::memo::MemoBytes;
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
#[serde_as]
#[serde(remote = "MemoBytes")] #[serde(remote = "MemoBytes")]
pub struct MemoBytesProxy( pub struct MemoBytesProxy(
#[serde_as(as = "serde_with::hex::Hex")]
#[serde(getter = "get_memo_bytes")] #[serde(getter = "get_memo_bytes")]
pub Vec<u8>, pub String,
); );
fn get_memo_bytes(memo: &MemoBytes) -> Vec<u8> { fn get_memo_bytes(memo: &MemoBytes) -> String {
memo.as_slice().to_vec() hex::encode(memo.as_slice())
} }
impl From<MemoBytesProxy> for MemoBytes { impl From<MemoBytesProxy> for MemoBytes {
fn from(p: MemoBytesProxy) -> MemoBytes { fn from(p: MemoBytesProxy) -> MemoBytes {
MemoBytes::from_bytes(&p.0).unwrap() MemoBytes::from_bytes(&hex::decode(&p.0).unwrap()).unwrap()
} }
} }