Skip to content

Commit

Permalink
TxBuilder: Implement CIP-0002 Coin Selection
Browse files Browse the repository at this point in the history
https://github.com/cardano-foundation/CIPs/blob/master/CIP-0002/CIP-0002.md

key differences
1) we take into account adjuting for free (which is out of CIP2's scope)
2) LargestFirst supports multiassets (naively)
  • Loading branch information
rooooooooob committed Oct 27, 2021
1 parent 692eb51 commit 7bffca8
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 21 deletions.
70 changes: 65 additions & 5 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ num-bigint = "0.4.0"
# feature or this one
clear_on_drop = { version = "0.2", features = ["no_cc"] }
itertools = "0.10.1"
rand = "0.8.4"

# non-wasm
[target.'cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))'.dependencies]
Expand Down
6 changes: 3 additions & 3 deletions rust/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl Deserialize for StakeCredential {
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
enum AddrType {
Base(BaseAddress),
Ptr(PointerAddress),
Expand All @@ -169,7 +169,7 @@ enum AddrType {
}

#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct ByronAddress(pub (crate) ExtendedAddr);
#[wasm_bindgen]
impl ByronAddress {
Expand Down Expand Up @@ -256,7 +256,7 @@ impl ByronAddress {
}

#[wasm_bindgen]
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct Address(AddrType);

from_bytes!(Address, data, {
Expand Down
8 changes: 4 additions & 4 deletions rust/src/legacy_address/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl cbor_event::de::Deserialize for AddrType {

type HDAddressPayload = Vec<u8>;

#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
#[derive(Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Attributes {
pub derivation_path: Option<HDAddressPayload>,
pub protocol_magic: Option<u32>,
Expand Down Expand Up @@ -182,10 +182,10 @@ fn hash_spending_data(addr_type: AddrType, xpub: &XPub, attrs: &Attributes) -> [
}

/// A valid cardano Address that is displayed in base58
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
#[derive(Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Addr(Vec<u8>);

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub enum AddressMatchXPub {
Yes,
No,
Expand Down Expand Up @@ -277,7 +277,7 @@ impl cbor_event::de::Deserialize for Addr {
const EXTENDED_ADDR_LEN: usize = 28;

/// A valid cardano address deconstructed
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct ExtendedAddr {
pub addr: [u8; EXTENDED_ADDR_LEN],
pub attributes: Attributes,
Expand Down
2 changes: 1 addition & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl TransactionInput {
}

#[wasm_bindgen]
#[derive(Clone, Debug)]
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]
pub struct TransactionOutput {
address: Address,
pub (crate) amount: Value,
Expand Down
Loading

0 comments on commit 7bffca8

Please sign in to comment.