value

Macro value 

Source
macro_rules! value {
    ($lovelace:expr $(,)?) => { ... };
    ($lovelace:expr, $( ($script_hash:literal, $asset_name:literal, $amount:expr $(,)?) ),+ $(,)? ) => { ... };
}
Expand description

Construct a Value<u64> from a lovelace amount and a list of assets.

The macro is variadic. In its first form, it only accepts a lovelace quantity. In its second second form, it accepts one or more asset as a triple.

The script hash and the asset name are expectd to be plain base16-encoded literals.

See also:

ยงexamples

assert_eq!(value!(123_456_789), Value::<u64>::new(123456789));
assert_eq!(
    value!(
        123_456_789,
        (
            "279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f",
            "534e454b",
            1_000_000,
        ),
    ),
    Value::new(123456789)
        .with_assets([
            (
                hash!("279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3f"),
                [( b"SNEK", 1_000_000)]
            ),
        ]),
);
assert_eq!(
    value!(
        0,
        (
            "b558ea5ecfa2a6e9701dab150248e94104402f789c090426eb60eb60",
            "536e656b6b696530393033",
            1,
        ),
        (
            "b558ea5ecfa2a6e9701dab150248e94104402f789c090426eb60eb60",
            "536e656b6b696533353536",
            1,
        ),
        (
            "a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235",
            "484f534b59",
            42_000_000,
        )
    ),
    Value::default()
        .with_assets([
            (
                hash!("b558ea5ecfa2a6e9701dab150248e94104402f789c090426eb60eb60"),
                vec![( Vec::from(b"Snekkie0903"), 1), ( Vec::from(b"Snekkie3556"), 1)],
            ),
            (
                hash!("a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235"),
                vec![( Vec::from(b"HOSKY"), 42_000_000)],
            ),
        ]),
);