From 5358f14730c424dce2d41de4ac5faf41016fa73f Mon Sep 17 00:00:00 2001 From: matiasbzurovski <164921079+matiasbzurovski@users.noreply.github.com> Date: Mon, 27 May 2024 16:14:41 +0200 Subject: [PATCH] Add percentage to TransactionGuarantee (#148) --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../ManifestBuildingTests.swift | 3 +- .../sargon/TransactionManifestTest.kt | 2 ++ .../manifest_building/modify_manifest.rs | 7 +++++ .../high_level/ret_api.rs | 1 + .../transaction_guarantee.rs | 31 ++++++++++++++++--- 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a07b9051b..e27415cc3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2586,7 +2586,7 @@ dependencies = [ [[package]] name = "sargon" -version = "1.0.2" +version = "1.0.3" dependencies = [ "actix-rt", "aes-gcm", diff --git a/Cargo.toml b/Cargo.toml index db4364687..c7c1582cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sargon" -version = "1.0.2" +version = "1.0.3" edition = "2021" build = "build.rs" diff --git a/apple/Tests/TestCases/RET/ManifestBuilding/ManifestBuildingTests.swift b/apple/Tests/TestCases/RET/ManifestBuilding/ManifestBuildingTests.swift index d726a809b..e576b8b30 100644 --- a/apple/Tests/TestCases/RET/ManifestBuilding/ManifestBuildingTests.swift +++ b/apple/Tests/TestCases/RET/ManifestBuilding/ManifestBuildingTests.swift @@ -190,7 +190,8 @@ final class ManifestBuildingTests: Test { var manifest = try rtm("transfer_1to2_multiple_nf_and_f_tokens") let guarantee = TransactionGuarantee( - amount: 642, + amount: 642, + percentage: 0.9, instructionIndex: 12, resourceAddress: .sampleStokenetXRD, resourceDivisibility: nil diff --git a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TransactionManifestTest.kt b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TransactionManifestTest.kt index c9bc20b81..6f9d433b7 100644 --- a/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TransactionManifestTest.kt +++ b/jvm/sargon-android/src/test/java/com/radixdlt/sargon/TransactionManifestTest.kt @@ -517,6 +517,8 @@ class TransactionManifestTest : SampleTestable { TransactionGuarantee( amount = 642.toDecimal192(), + percentage = + 1.toDecimal192(), instructionIndex = 12.toULong(), resourceAddress = diff --git a/src/wrapped_radix_engine_toolkit/high_level/manifest_building/modify_manifest.rs b/src/wrapped_radix_engine_toolkit/high_level/manifest_building/modify_manifest.rs index c57775ec8..e84e88bc6 100644 --- a/src/wrapped_radix_engine_toolkit/high_level/manifest_building/modify_manifest.rs +++ b/src/wrapped_radix_engine_toolkit/high_level/manifest_building/modify_manifest.rs @@ -211,6 +211,7 @@ CALL_METHOD let index = 2; let resource = ResourceAddress::sample_mainnet_candy(); let added_guaranteed_amount: Decimal = "0.12344".parse().unwrap(); + let percentage: Decimal = "0.95".parse().unwrap(); let divisibility = 4; let rounded_guaranteed_amount: Decimal = "0.1234".parse().unwrap(); assert_eq!( @@ -225,6 +226,7 @@ CALL_METHOD .unwrap(); manifest = manifest.modify_add_guarantees([TransactionGuarantee::new( added_guaranteed_amount, + percentage, index, resource, divisibility, @@ -352,6 +354,7 @@ CALL_METHOD manifest_eq( manifest.modify_add_guarantees([TransactionGuarantee::new( 1337, + 0, 1, ResourceAddress::sample(), 10, @@ -389,6 +392,7 @@ CALL_METHOD manifest_eq( manifest.modify_add_guarantees([TransactionGuarantee::new( 1337, + 0, 1, ResourceAddress::sample(), 10, @@ -461,6 +465,7 @@ CALL_METHOD assert_eq!( manifest.clone().modify_add_guarantees([ TransactionGuarantee::new( + 0, 0, 4, ResourceAddress::sample(), @@ -484,6 +489,7 @@ CALL_METHOD TransactionGuarantee::new( i, 0, + 0, ResourceAddress::sample(), None, ) @@ -504,6 +510,7 @@ CALL_METHOD modify_manifest_add_guarantees( manifest.clone(), vec![TransactionGuarantee::new( + 0, 0, 5, ResourceAddress::sample(), diff --git a/src/wrapped_radix_engine_toolkit/high_level/ret_api.rs b/src/wrapped_radix_engine_toolkit/high_level/ret_api.rs index cffedddcb..1a9ef697e 100644 --- a/src/wrapped_radix_engine_toolkit/high_level/ret_api.rs +++ b/src/wrapped_radix_engine_toolkit/high_level/ret_api.rs @@ -399,6 +399,7 @@ mod tests { let modified = modify_manifest_add_guarantees( manifest, vec![TransactionGuarantee::new( + 0, 0, 0, ResourceAddress::sample(), diff --git a/src/wrapped_radix_engine_toolkit/high_level/sargon_specific_types/transaction_guarantee.rs b/src/wrapped_radix_engine_toolkit/high_level/sargon_specific_types/transaction_guarantee.rs index a0a1fdf5e..275f1accc 100644 --- a/src/wrapped_radix_engine_toolkit/high_level/sargon_specific_types/transaction_guarantee.rs +++ b/src/wrapped_radix_engine_toolkit/high_level/sargon_specific_types/transaction_guarantee.rs @@ -2,7 +2,11 @@ use crate::prelude::*; #[derive(Clone, Debug, PartialEq, Eq, Hash, uniffi::Record)] pub struct TransactionGuarantee { + /// The guaranteed amount to be obtained on this transaction. For manifest & display purposes. pub amount: Decimal192, + + /// The percentage the user has selected, which generated the `amount`. For display purposes only. + pub percentage: Decimal192, pub instruction_index: u64, pub resource_address: ResourceAddress, pub resource_divisibility: Option, @@ -11,12 +15,14 @@ pub struct TransactionGuarantee { impl TransactionGuarantee { pub fn new( amount: impl Into, + percentage: impl Into, instruction_index: u64, resource_address: ResourceAddress, resource_divisibility: impl Into>, ) -> Self { Self { amount: amount.into(), + percentage: percentage.into(), instruction_index, resource_address, resource_divisibility: resource_divisibility.into(), @@ -32,11 +38,23 @@ impl TransactionGuarantee { impl HasSampleValues for TransactionGuarantee { fn sample() -> Self { - TransactionGuarantee::new(1337, 3, ResourceAddress::sample(), Some(12)) + TransactionGuarantee::new( + 1337, + "0.95".parse::().unwrap(), + 3, + ResourceAddress::sample(), + Some(12), + ) } fn sample_other() -> Self { - TransactionGuarantee::new(42, 12, ResourceAddress::sample_other(), None) + TransactionGuarantee::new( + 42, + "0.90".parse::().unwrap(), + 12, + ResourceAddress::sample_other(), + None, + ) } } @@ -60,8 +78,13 @@ mod tests { #[test] fn rounding() { - let sut = - SUT::new("0.12344", 2, ResourceAddress::sample_mainnet_candy(), 4); + let sut = SUT::new( + "0.12344", + 90, + 2, + ResourceAddress::sample_mainnet_candy(), + 4, + ); assert_eq!(sut.rounded_amount(), "0.1234".into()); }