Skip to content

Commit a34384f

Browse files
committed
feat: wup wip wuip
1 parent 81e0ff7 commit a34384f

File tree

4 files changed

+80
-10
lines changed

4 files changed

+80
-10
lines changed

packages/sdk/src/tx/tx.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,13 +484,23 @@ export class Tx {
484484
// Wrapper fee payer is always defined at this point
485485
wrapperFeePayer: wrapperTx.wrapperFeePayer!,
486486
commitments: commitments.map(
487-
({ txType, hash, txCodeId, data, memo, maspTxIn, maspTxOut }) => ({
487+
({
488+
txType,
489+
hash,
490+
txCodeId,
491+
data,
492+
memo,
493+
maspTxIn,
494+
maspTxOut,
495+
maspTxConv,
496+
}) => ({
488497
txType: txType as TxType,
489498
hash,
490499
txCodeId,
491500
memo,
492501
maspTxIn,
493502
maspTxOut,
503+
maspTxConv,
494504
...getProps(txType, data),
495505
})
496506
),

packages/shared/lib/src/sdk/tx.rs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use gloo_utils::format::JsValueSerdeExt;
55
use namada_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
66
use namada_sdk::collections::HashSet;
77
use namada_sdk::masp_primitives::transaction::components::sapling::builder::StoredBuildParams;
8-
use namada_sdk::masp_primitives::transaction::components::sapling::fees::{InputView, OutputView};
8+
use namada_sdk::masp_primitives::transaction::components::sapling::fees::{ConvertView, InputView, OutputView};
9+
use namada_sdk::masp_primitives::transaction::components::I128Sum;
910
use namada_sdk::masp_primitives::zip32::ExtendedFullViewingKey;
1011
use namada_sdk::signing::SigningTxData;
1112
use namada_sdk::token::{Amount, DenominatedAmount, Transfer};
@@ -264,15 +265,22 @@ pub fn deserialize_tx(tx_bytes: Vec<u8>, wasm_hashes: JsValue) -> Result<Vec<u8>
264265
Ok(borsh::to_vec(&tx)?)
265266
}
266267

267-
#[derive(BorshSerialize, BorshDeserialize)]
268+
#[derive(Debug, BorshSerialize, BorshDeserialize)]
268269
#[borsh(crate = "namada_sdk::borsh")]
269270
pub struct TxIn {
270271
pub token: String,
271272
pub value: String,
272273
pub owner: String,
273274
}
274275

275-
#[derive(BorshSerialize, BorshDeserialize)]
276+
#[derive(Debug, BorshSerialize, BorshDeserialize)]
277+
#[borsh(crate = "namada_sdk::borsh")]
278+
pub struct TxConv {
279+
pub token: String,
280+
pub value: String,
281+
}
282+
283+
#[derive(Debug, BorshSerialize, BorshDeserialize)]
276284
#[borsh(crate = "namada_sdk::borsh")]
277285
pub struct TxOut {
278286
pub token: String,
@@ -290,6 +298,7 @@ pub struct Commitment {
290298
memo: Option<String>,
291299
masp_tx_in: Option<Vec<TxIn>>,
292300
masp_tx_out: Option<Vec<TxOut>>,
301+
masp_tx_conv: Option<Vec<TxConv>>,
293302
}
294303

295304
#[derive(BorshSerialize, BorshDeserialize)]
@@ -352,7 +361,12 @@ impl TxDetails {
352361
let tx_kind = transaction::TransactionKind::from(tx_type, &tx_data);
353362
let data = tx_kind.to_bytes()?;
354363

355-
let (inputs, outputs) = get_masp_details(&tx, &tx_kind);
364+
let (inputs, outputs, conversions) = get_masp_details(&tx, &tx_kind);
365+
366+
web_sys::console::log_1(&format!(
367+
"Conversions: {:?}",
368+
conversions
369+
).into());
356370

357371
commitments.push(Commitment {
358372
tx_type,
@@ -362,6 +376,7 @@ impl TxDetails {
362376
memo,
363377
masp_tx_out: outputs,
364378
masp_tx_in: inputs,
379+
masp_tx_conv: conversions,
365380
});
366381
}
367382
}
@@ -380,7 +395,7 @@ impl TxDetails {
380395
fn get_masp_details(
381396
tx: &tx::Tx,
382397
tx_kind: &transaction::TransactionKind,
383-
) -> (Option<Vec<TxIn>>, Option<Vec<TxOut>>) {
398+
) -> (Option<Vec<TxIn>>, Option<Vec<TxOut>>, Option<Vec<TxConv>>) {
384399
let parse = |transfer: &Transfer| {
385400
if let Some(shielded_hash) = transfer.shielded_section_hash {
386401
let masp_builder = tx
@@ -410,6 +425,29 @@ fn get_masp_details(
410425
})
411426
.collect::<Vec<_>>();
412427

428+
let conversions = masp_builder.builder.sapling_converts().
429+
iter()
430+
.map(|convert| {
431+
let asset_data = asset_types
432+
.iter()
433+
.find(|ad| {
434+
let conv_asset_types = I128Sum::from(convert.conversion().clone()).asset_types()
435+
.cloned().collect::<Vec<_>>();
436+
let ad = ad.encode().unwrap();
437+
438+
conv_asset_types.into_iter().any(|w| w == ad)
439+
})
440+
.expect("Asset data to exist");
441+
442+
let amount = Amount::from_u64(convert.value());
443+
let denominated_amount = DenominatedAmount::new(amount, asset_data.denom);
444+
445+
TxConv {
446+
token: asset_data.token.to_string(),
447+
value: denominated_amount.to_string(),
448+
}
449+
}).collect::<Vec<_>>();
450+
413451
let outputs = masp_builder
414452
.builder
415453
.sapling_outputs()
@@ -431,19 +469,19 @@ fn get_masp_details(
431469
})
432470
.collect::<Vec<_>>();
433471

434-
(Some(inputs), Some(outputs))
472+
(Some(inputs), Some(outputs), Some(conversions))
435473
} else {
436-
(None, None)
474+
(None, None, None)
437475
}
438476
};
439477

440478
match tx_kind {
441479
transaction::TransactionKind::IbcTransfer(ibc_transfer) => match &ibc_transfer.transfer {
442480
Some(transfer) => parse(transfer),
443-
None => (None, None),
481+
None => (None, None, None),
444482
},
445483
transaction::TransactionKind::Transfer(transfer) => parse(transfer),
446-
_ => (None, None),
484+
_ => (None, None , None),
447485
}
448486
}
449487

packages/types/src/tx/schema/txDetails.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ export class MaspTxOut {
3232
}
3333
}
3434

35+
export class MaspTxConv {
36+
@field({ type: "string" })
37+
token!: string;
38+
39+
@field({ type: "string" })
40+
value!: string;
41+
42+
constructor(data: MaspTxConv) {
43+
Object.assign(this, data);
44+
}
45+
}
46+
3547
export class CommitmentMsgValue {
3648
@field({ type: "u8" })
3749
txType!: number;
@@ -54,6 +66,9 @@ export class CommitmentMsgValue {
5466
@field({ type: option(vec(MaspTxOut)) })
5567
maspTxOut?: MaspTxOut[];
5668

69+
@field({ type: option(vec(MaspTxConv)) })
70+
maspTxConv?: MaspTxConv[];
71+
5772
constructor(data: CommitmentMsgValue) {
5873
const maspTxIn =
5974
data.maspTxIn ?
@@ -63,11 +78,16 @@ export class CommitmentMsgValue {
6378
data.maspTxOut ?
6479
data.maspTxOut.map((txOut) => new MaspTxOut(txOut))
6580
: undefined;
81+
const maspTxConv =
82+
data.maspTxConv ?
83+
data.maspTxConv.map((txConv) => new MaspTxConv(txConv))
84+
: undefined;
6685

6786
Object.assign(this, {
6887
...data,
6988
maspTxIn,
7089
maspTxOut,
90+
maspTxConv,
7191
});
7292
}
7393
}

packages/types/src/tx/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ClaimRewardsMsgValue,
55
EthBridgeTransferMsgValue,
66
IbcTransferMsgValue,
7+
MaspTxConv,
78
MaspTxIn,
89
MaspTxOut,
910
RedelegateMsgValue,
@@ -75,6 +76,7 @@ export type CommitmentDetailProps = SupportedTxProps & {
7576
memo?: string;
7677
maspTxIn?: MaspTxIn[];
7778
maspTxOut?: MaspTxOut[];
79+
maspTxConv?: MaspTxConv[];
7880
};
7981

8082
export type TxDetails = WrapperTxProps & {

0 commit comments

Comments
 (0)