Skip to content

Commit

Permalink
Add support for NFT transfer by IDs; Bump version; (radixdlt#28)
Browse files Browse the repository at this point in the history
* Add support for NFT transfer by IDs
* Bump version
  • Loading branch information
siy authored Jun 12, 2023
1 parent b5c37d2 commit 0320b10
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "babylon-ledger-app"
version = "0.3.4"
version = "0.3.5"
authors = ["siy"]
edition = "2021"
description = "Radix Babylon"
Expand Down
19 changes: 18 additions & 1 deletion sbor/src/print/instruction_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ mod tests {
Self {
extractor: InstructionExtractor::new(),
ins_printer: InstructionPrinter::new(NetworkId::LocalNet, tty),
tx_printer: TxIntentPrinter::new(NetworkId::LocalNet),
tx_printer: TxIntentPrinter::new(),
}
}

Expand Down Expand Up @@ -746,6 +746,23 @@ br##"
}, TxIntentType::Transfer)
}

#[test]
pub fn test_simple_transfer_nft_by_id() {
check_partial_decoding_with_type(&TX_SIMPLE_TRANSFER_NFT_BY_ID,
br##"
1 of 4: CallMethod Address(account_loc1qjy5fakwygc45fkyhyxxulsf5zfae0ycez0x05et9hqsshmat9) "lock_fee" Tuple(Decimal(10), )
2 of 4: CallMethod Address(account_loc1qjy5fakwygc45fkyhyxxulsf5zfae0ycez0x05et9hqsshmat9) "withdraw_non_fungibles" Tuple(Address(resource_loc1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpwwehl), Array<NonFungibleLocalId>(#1u64#, #2u64#, #3u64#, ), )
3 of 4: TakeFromWorktopByIds Array<NonFungibleLocalId>(#1u64#, #2u64#, #3u64#, ) Address(resource_loc1qgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqpwwehl)
4 of 4: CallMethod Address(account_loc1pxhyn798qaehnxz6qwyj6jx5qm296j4j5uuqh4av7h5saywq8x) "deposit" Tuple(Bucket(0u32), )
"##, &DetectedTxType::Transfer {
fee: Some(Decimal::whole(10)),
src_address: Address::from_array([0x04, 0x89, 0x44, 0xf6, 0xce, 0x22, 0x31, 0x5a, 0x26, 0xc4, 0xb9, 0x0c, 0x6e, 0x7e, 0x09, 0xa0, 0x93, 0xdc, 0xbc, 0x98, 0xc8, 0x9e, 0x67, 0xd3, 0x2b, 0x2d, 0xc1,]),
dst_address: Address::from_array([0x09, 0xae, 0x49, 0xf8, 0xa7, 0x07, 0x73, 0x79, 0x98, 0x5a, 0x03, 0x89, 0x2d, 0x48, 0xd4, 0x06, 0xd4, 0x5d, 0x4a, 0xb2, 0xa7, 0x38, 0x0b, 0xd7, 0xac, 0xf5, 0xe9,]),
res_address: Address::from_array([0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,]),
amount: Decimal::whole(3)
}, TxIntentType::Transfer)
}

#[test]
pub fn test_simple_transfer_with_multiple_locked_fees() {
check_partial_decoding_with_type(&TX_SIMPLE_TRANSFER_WITH_MULTIPLE_LOCKED_FEES,
Expand Down
19 changes: 18 additions & 1 deletion sbor/src/print/tx_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ pub enum FeePhase {

// Summary:
// Start -> CallMethod -> AddressWithdraw -> ExpectWithdraw + ("withdraw") ->
// WithdrawDone (+ TakeFromWorktopByAmount) -> ValueDeposit -> Resource -> ResourceDone + end of instruction ->
// /- WithdrawDone (+ TakeFromWorktopByAmount) -> ValueDeposit -> Resource -> ResourceDone + end of instruction ->
// \- WithdrawDone (+ TakeFromWorktopByIds) -> ValueCountDeposit -> ValueCountDepositIds -> ValueCountDone -> Resource -> ResourceDone + end of instruction ->
// ExpectDepositCall (+ CallMethod) -> AddressDeposit -> ExpectDeposit + ("deposit") -> DoneTransfer

#[derive(Copy, Clone, PartialEq)]
Expand All @@ -39,6 +40,9 @@ pub enum DecodingPhase {
AddressWithdraw,
ExpectWithdraw,
WithdrawDone,
ValueCountDeposit,
ValueCountDepositIds,
ValueCountDone,
ValueDeposit,
Resource,
ResourceDone,
Expand Down Expand Up @@ -325,6 +329,9 @@ impl TxIntentPrinter {
(DecodingPhase::WithdrawDone, Instruction::TakeFromWorktopByAmount) => {
self.decoding_phase = DecodingPhase::ValueDeposit;
}
(DecodingPhase::WithdrawDone, Instruction::TakeFromWorktopByIds) => {
self.decoding_phase = DecodingPhase::ValueCountDeposit;
}
(DecodingPhase::ExpectDepositCall, Instruction::CallMethod) => {
self.decoding_phase = DecodingPhase::AddressDeposit;
}
Expand Down Expand Up @@ -353,9 +360,15 @@ impl TxIntentPrinter {
(DecodingPhase::AddressWithdraw, 1) => {
self.decoding_phase = DecodingPhase::ExpectWithdraw;
}
(DecodingPhase::ValueCountDeposit, 0) => {
self.decoding_phase = DecodingPhase::ValueCountDepositIds;
}
(DecodingPhase::ExpectDepositCall, 0) => {
self.decoding_phase = DecodingPhase::AddressDeposit;
}
(DecodingPhase::ValueCountDone, 1) => {
self.decoding_phase = DecodingPhase::Resource;
}

(_, _) => {}
};
Expand All @@ -374,6 +387,10 @@ impl TxIntentPrinter {
fn parameter_data(&mut self, source_event: SborEvent) {
match source_event {
SborEvent::Data(data) => self.data.push(data),
SborEvent::Len(len) if self.decoding_phase == DecodingPhase::ValueCountDepositIds => {
self.amount = Decimal::whole(len.into());
self.decoding_phase = DecodingPhase::ValueCountDone;
}
_ => {}
}
}
Expand Down
28 changes: 28 additions & 0 deletions sbor/src/tx_intent_test_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,34 @@ pub mod tests {
0xf5, 0xe9, 0x0c, 0x07, 0x64, 0x65, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x21, 0x01, 0x81, 0x00,
0x00, 0x00, 0x00, 0x20, 0x20, 0x00,
];
pub const TX_SIMPLE_TRANSFER_NFT_BY_ID: [u8; 387] = [
0x4d, 0x21, 0x02, 0x21, 0x09, 0x07, 0x01, 0x07, 0x0c, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0a, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x05, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x01, 0x01, 0x20, 0x07, 0x20, 0xf3, 0x81, 0x62,
0x6e, 0x41, 0xe7, 0x02, 0x7e, 0xa4, 0x31, 0xbf, 0xe3, 0x00, 0x9e, 0x94, 0xbd, 0xd2, 0x5a,
0x74, 0x6b, 0xee, 0xc4, 0x68, 0x94, 0x8d, 0x6c, 0x3c, 0x7c, 0x5d, 0xc9, 0xa5, 0x4b, 0x01,
0x00, 0x09, 0x40, 0x42, 0x0f, 0x00, 0x08, 0x03, 0x00, 0x21, 0x02, 0x20, 0x22, 0x04, 0x21,
0x03, 0x80, 0x04, 0x89, 0x44, 0xf6, 0xce, 0x22, 0x31, 0x5a, 0x26, 0xc4, 0xb9, 0x0c, 0x6e,
0x7e, 0x09, 0xa0, 0x93, 0xdc, 0xbc, 0x98, 0xc8, 0x9e, 0x67, 0xd3, 0x2b, 0x2d, 0xc1, 0x0c,
0x08, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x66, 0x65, 0x65, 0x21, 0x01, 0x85, 0x00, 0x00, 0xe8,
0x89, 0x04, 0x23, 0xc7, 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21,
0x03, 0x80, 0x04, 0x89, 0x44, 0xf6, 0xce, 0x22, 0x31, 0x5a, 0x26, 0xc4, 0xb9, 0x0c, 0x6e,
0x7e, 0x09, 0xa0, 0x93, 0xdc, 0xbc, 0x98, 0xc8, 0x9e, 0x67, 0xd3, 0x2b, 0x2d, 0xc1, 0x0c,
0x16, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x5f, 0x6e, 0x6f, 0x6e, 0x5f, 0x66,
0x75, 0x6e, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x73, 0x21, 0x02, 0x80, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x87, 0x03, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x20, 0x87, 0x03, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x80, 0x02, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x03, 0x80, 0x09, 0xae, 0x49, 0xf8,
0xa7, 0x07, 0x73, 0x79, 0x98, 0x5a, 0x03, 0x89, 0x2d, 0x48, 0xd4, 0x06, 0xd4, 0x5d, 0x4a,
0xb2, 0xa7, 0x38, 0x0b, 0xd7, 0xac, 0xf5, 0xe9, 0x0c, 0x07, 0x64, 0x65, 0x70, 0x6f, 0x73,
0x69, 0x74, 0x21, 0x01, 0x81, 0x00, 0x00, 0x00, 0x00, 0x20, 0x20, 0x00,
];
pub const TX_SIMPLE_TRANSFER_WITH_MULTIPLE_LOCKED_FEES: [u8; 454] = [
0x4d, 0x21, 0x02, 0x21, 0x09, 0x07, 0x01, 0x07, 0x0c, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0a, 0xe8, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x05, 0x00,
Expand Down
4 changes: 4 additions & 0 deletions sbor/src/tx_intent_test_data_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ pub mod tests {
name: "simple_transfer_nft",
data: &TX_SIMPLE_TRANSFER_NFT,
},
Blob {
name: "simple_transfer_nft_by_id",
data: &TX_SIMPLE_TRANSFER_NFT_BY_ID,
},
Blob {
name: "simple_transfer_with_multiple_locked_fees",
data: &TX_SIMPLE_TRANSFER_WITH_MULTIPLE_LOCKED_FEES,
Expand Down
Binary file added test/data/simple_transfer_nft_by_id.txn
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test-get-application-version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
print("Testing", "GetAppVersion", instructionCode, end=" ")
response = dongle.exchange(bytes.fromhex(instructionClass + instructionCode + p1 + p2 + dataLength))

assert response.hex() == '000304', "Invalid version\nReceived:" + response.hex()
assert response.hex() == '000305', "Invalid version\nReceived:" + response.hex()
print("Success")

0 comments on commit 0320b10

Please sign in to comment.