Skip to content

Commit 8268126

Browse files
authored
Merge branch 'master' into ptr-addr-u64
2 parents 1e16c32 + adb5204 commit 8268126

File tree

7 files changed

+57
-23
lines changed

7 files changed

+57
-23
lines changed

doc/getting-started/generating-transactions.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ Fees are automatically calculated and sent to a change address in the example.
2525

2626
```javascript
2727
// instantiate the tx builder with the Cardano protocol parameters - these may change later on
28-
const txBuilder = CardanoWasm.TransactionBuilder.new(
29-
// all of these are taken from the mainnet genesis settings
30-
// linear fee parameters (a*size + b)
31-
CardanoWasm.LinearFee.new(CardanoWasm.BigNum.from_str('44'), CardanoWasm.BigNum.from_str('155381')),
32-
// minimum utxo value
33-
CardanoWasm.BigNum.from_str('1000000'),
34-
// pool deposit
35-
CardanoWasm.BigNum.from_str('500000000'),
36-
// key deposit
37-
CardanoWasm.BigNum.from_str('2000000')
28+
const linearFee = CardanoWasm.LinearFee.new(
29+
CardanoWasm.BigNum.from_str('44'),
30+
CardanoWasm.BigNum.from_str('155381')
3831
);
32+
const txBuilderCfg = CardanoWasm.TransactionBuilderConfigBuilder.new()
33+
.fee_algo(linearFee)
34+
.pool_deposit(CardanoWasm.BigNum.from_str('500000000'))
35+
.key_deposit(CardanoWasm.BigNum.from_str('2000000'))
36+
.max_value_size(4000)
37+
.max_tx_size(8000)
38+
.coins_per_utxo_word(CardanoWasm.BigNum.from_str('34482'))
39+
.build();
40+
const txBuilder = CardanoWasm.TransactionBuilder.new(txBuilderCfg);
3941

4042
// add a keyhash input - for ADA held in a Shelley-era normal address (Base, Enterprise, Pointer)
4143
const prvKey = CardanoWasm.PrivateKey.from_bech32("ed25519e_sk16rl5fqqf4mg27syjzjrq8h3vq44jnnv52mvyzdttldszjj7a64xtmjwgjtfy25lu0xmv40306lj9pcqpa6slry9eh3mtlqvfjz93vuq0grl80");
@@ -80,22 +82,27 @@ txBuilder.add_output(
8082
txBuilder.set_ttl(410021);
8183

8284
// calculate the min fee required and send any change to an address
83-
txBuilder.add_change_if_needed(shelleyChangeAddress)
85+
txBuilder.add_change_if_needed(shelleyChangeAddress);
8486

8587
// once the transaction is ready, we build it to get the tx body without witnesses
8688
const txBody = txBuilder.build();
8789
const txHash = CardanoWasm.hash_transaction(txBody);
8890
const witnesses = CardanoWasm.TransactionWitnessSet.new();
8991

9092
// add keyhash witnesses
91-
const vkeyWitnesses = CardanoWasm.VkeyWitnesses.new();
93+
const vkeyWitnesses = CardanoWasm.Vkeywitnesses.new();
9294
const vkeyWitness = CardanoWasm.make_vkey_witness(txHash, prvKey);
9395
vkeyWitnesses.add(vkeyWitness);
9496
witnesses.set_vkeys(vkeyWitnesses);
9597

9698
// add bootstrap (Byron-era) witnesses
99+
const cip1852Account = CardanoWasm.Bip32PrivateKey.from_bech32('xprv1hretan5mml3tq2p0twkhq4tz4jvka7m2l94kfr6yghkyfar6m9wppc7h9unw6p65y23kakzct3695rs32z7vaw3r2lg9scmfj8ec5du3ufydu5yuquxcz24jlkjhsc9vsa4ufzge9s00fn398svhacse5su2awrw');
97100
const bootstrapWitnesses = CardanoWasm.BootstrapWitnesses.new();
98-
const bootstrapWitness = CardanoWasm.make_icarus_bootstrap_witness(txHash,byronAddress,getCip1852Account());
101+
const bootstrapWitness = CardanoWasm.make_icarus_bootstrap_witness(
102+
txHash,
103+
byronAddress,
104+
cip1852Account,
105+
);
99106
bootstrapWitnesses.add(bootstrapWitness);
100107
witnesses.set_bootstraps(bootstrapWitnesses);
101108

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cardano-serialization-lib",
3-
"version": "10.0.3",
3+
"version": "10.0.4",
44
"description": "(De)serialization functions for the Cardano blockchain along with related utility functions",
55
"scripts": {
66
"rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack) && npm run js:flowgen",

rust/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
[package]
22
name = "cardano-serialization-lib"
3-
version = "10.0.3"
3+
version = "10.0.4"
44
edition = "2018"
55
authors = ["EMURGO"]
66
license = "MIT"
77
description = "(De)serialization functions for the Cardano blockchain along with related utility functions"
88
documentation = "https://docs.cardano.org/cardano-components/cardano-serialization-lib"
99
repository = "https://github.com/Emurgo/cardano-serialization-lib"
10+
readme="../README.md"
1011
exclude = [
1112
"pkg/*",
1213
]

rust/src/plutus.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,12 +1272,12 @@ mod tests {
12721272
// witness_set should have fixed length array
12731273
let mut witness_set = TransactionWitnessSet::new();
12741274
witness_set.set_plutus_data(&list);
1275-
assert_eq!("a1048101", hex::encode(witness_set.to_bytes()));
1275+
assert_eq!("a1049f01ff", hex::encode(witness_set.to_bytes()));
12761276

12771277
list = PlutusList::new();
12781278
list.add(&datum);
12791279
witness_set.set_plutus_data(&list);
1280-
assert_eq!(format!("a10481{}", datum_cli), hex::encode(witness_set.to_bytes()));
1280+
assert_eq!(format!("a1049f{}ff", datum_cli), hex::encode(witness_set.to_bytes()));
12811281
}
12821282

12831283
#[test]
@@ -1287,4 +1287,33 @@ mod tests {
12871287
let new_bytes = datums.to_bytes();
12881288
assert_eq!(orig_bytes, new_bytes);
12891289
}
1290+
1291+
#[test]
1292+
pub fn test_cost_model() {
1293+
let arr = vec![
1294+
197209, 0, 1, 1, 396231, 621, 0, 1, 150000, 1000, 0, 1, 150000, 32,
1295+
2477736, 29175, 4, 29773, 100, 29773, 100, 29773, 100, 29773, 100, 29773,
1296+
100, 29773, 100, 100, 100, 29773, 100, 150000, 32, 150000, 32, 150000, 32,
1297+
150000, 1000, 0, 1, 150000, 32, 150000, 1000, 0, 8, 148000, 425507, 118,
1298+
0, 1, 1, 150000, 1000, 0, 8, 150000, 112536, 247, 1, 150000, 10000, 1,
1299+
136542, 1326, 1, 1000, 150000, 1000, 1, 150000, 32, 150000, 32, 150000,
1300+
32, 1, 1, 150000, 1, 150000, 4, 103599, 248, 1, 103599, 248, 1, 145276,
1301+
1366, 1, 179690, 497, 1, 150000, 32, 150000, 32, 150000, 32, 150000, 32,
1302+
150000, 32, 150000, 32, 148000, 425507, 118, 0, 1, 1, 61516, 11218, 0, 1,
1303+
150000, 32, 148000, 425507, 118, 0, 1, 1, 148000, 425507, 118, 0, 1, 1,
1304+
2477736, 29175, 4, 0, 82363, 4, 150000, 5000, 0, 1, 150000, 32, 197209, 0,
1305+
1, 1, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000, 32, 150000,
1306+
32, 150000, 32, 3345831, 1, 1,
1307+
];
1308+
let cm = arr.iter().fold((CostModel::new(), 0), |(mut cm, i), x| {
1309+
cm.set(i, &Int::new_i32(x.clone()));
1310+
(cm, i + 1)
1311+
}).0;
1312+
let mut cms = Costmdls::new();
1313+
cms.insert(&Language::new_plutus_v1(), &cm);
1314+
assert_eq!(
1315+
hex::encode(cms.language_views_encoding()),
1316+
"a141005901d59f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f704001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff"
1317+
);
1318+
}
12901319
}

rust/src/serialization.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,10 +1806,7 @@ impl cbor_event::se::Serialize for TransactionWitnessSet {
18061806
}
18071807
if let Some(field) = &self.plutus_data {
18081808
serializer.write_unsigned_integer(4)?;
1809-
serializer.write_array(cbor_event::Len::Len(field.len() as u64))?;
1810-
for i in 0..field.len() {
1811-
field.get(i).serialize(serializer)?;
1812-
}
1809+
field.serialize(serializer)?;
18131810
}
18141811
if let Some(field) = &self.redeemers {
18151812
serializer.write_unsigned_integer(5)?;

0 commit comments

Comments
 (0)