Skip to content

Commit da6eba2

Browse files
authored
Merge pull request #231 from Emurgo/ruslan/add-mint-and-metadata
Mint and simpler metadata in tx-builder
2 parents 87ccdae + 07c72a3 commit da6eba2

File tree

7 files changed

+1497
-215
lines changed

7 files changed

+1497
-215
lines changed

.github/workflows/pr-checks.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,30 @@ jobs:
4141
- name: rust:build-browser
4242
run: |
4343
npm run rust:build-browser
44+
check-warns:
45+
if: github.event.review && (github.event.review.state == 'approved' || contains(github.event.review.body, '/check'))
46+
runs-on: ubuntu-latest
47+
steps:
48+
- uses: actions/checkout@v2
49+
with:
50+
submodules: 'recursive'
51+
- uses: actions/setup-node@v1
52+
with:
53+
node-version: '12.18.1'
54+
- name: Cache node modules
55+
uses: actions/cache@v1
56+
with:
57+
path: ~/.npm # npm cache files are stored in `~/.npm` on Linux/macOS
58+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
59+
restore-keys: |
60+
${{ runner.os }}-build-${{ env.cache-name }}-
61+
${{ runner.os }}-build-
62+
${{ runner.os }}-
63+
- name: prepare-rust
64+
run: |
65+
rustup install stable
66+
rustup target add wasm32-unknown-unknown --toolchain stable
67+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
68+
- name: rust:check-warnings
69+
run: |
70+
npm run rust:check-warnings

package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
"rust:build-asm": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=browser; wasm-pack pack) && npm run asm:build && npm run js:flowgen",
1010
"rust:publish": "cd rust && cargo publish && cd ../",
1111
"asm:build": "./binaryen/bin/wasm2js ./rust/pkg/cardano_serialization_lib_bg.wasm --output ./rust/pkg/cardano_serialization_lib.asm.js && node ./scripts/wasm-to-asm",
12+
"rust:check-warnings": "(cd rust; RUSTFLAGS=\"-D warnings\" cargo +stable build)",
1213
"rust:test": "(cd rust; cargo test)",
1314
"js:flowgen": "flowgen ./rust/pkg/cardano_serialization_lib.d.ts -o ./rust/pkg/cardano_serialization_lib.js.flow --add-flow-header",
1415
"js:prepublish": "npm run rust:test && rimraf ./publish && cp -r ./rust/pkg ./publish && cp README.md publish/ && cp LICENSE publish/",
15-
"js:publish-nodejs": "npm run rust:build-nodejs && npm run js:prepublish && node ./scripts/publish-helper -nodejs && cd publish && npm publish --access public",
16-
"js:publish-browser": "npm run rust:build-browser && npm run js:prepublish && node ./scripts/publish-helper -browser && cd publish && npm publish --access public",
17-
"js:publish-asm": "npm run rust:build-asm && npm run js:prepublish && node ./scripts/publish-helper -asmjs && cd publish && npm publish --access public",
16+
"js:publish-nodejs:prod": "npm run rust:build-nodejs && npm run js:prepublish && node ./scripts/publish-helper -nodejs && cd publish && npm publish --access public",
17+
"js:publish-nodejs:beta": "npm run rust:build-nodejs && npm run js:prepublish && node ./scripts/publish-helper -nodejs && cd publish && npm publish --tag beta --access public",
18+
"js:publish-browser:prod": "npm run rust:build-browser && npm run js:prepublish && node ./scripts/publish-helper -browser && cd publish && npm publish --access public",
19+
"js:publish-browser:beta": "npm run rust:build-browser && npm run js:prepublish && node ./scripts/publish-helper -browser && cd publish && npm publish --tag beta --access public",
20+
"js:publish-asm:prod": "npm run rust:build-asm && npm run js:prepublish && node ./scripts/publish-helper -asmjs && cd publish && npm publish --access public",
21+
"js:publish-asm:beta": "npm run rust:build-asm && npm run js:prepublish && node ./scripts/publish-helper -asmjs && cd publish && npm publish --tag beta --access public",
1822
"postinstall": "git submodule update --init --recursive && cd binaryen; cmake . && make"
1923
},
2024
"husky": {

rust/pkg/cardano_serialization_lib.js.flow

Lines changed: 205 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ declare export var RedeemerTagKind: {|
293293
+Reward: 3, // 3
294294
|};
295295

296+
/**
297+
*/
298+
299+
declare export var CoinSelectionStrategyCIP2: {|
300+
+LargestFirst: 0, // 0
301+
+RandomImprove: 1, // 1
302+
|};
303+
296304
/**
297305
* Used to choosed the schema for a script JSON string
298306
*/
@@ -322,14 +330,6 @@ declare export var MetadataJsonSchema: {|
322330
+DetailedSchema: 2, // 2
323331
|};
324332

325-
/**
326-
*/
327-
328-
declare export var CoinSelectionStrategyCIP2: {|
329-
+LargestFirst: 0, // 0
330-
+RandomImprove: 1, // 1
331-
|};
332-
333333
/**
334334
*/
335335

@@ -2434,6 +2434,13 @@ declare export class Mint {
24342434
*/
24352435
static new(): Mint;
24362436

2437+
/**
2438+
* @param {ScriptHash} key
2439+
* @param {MintAssets} value
2440+
* @returns {Mint}
2441+
*/
2442+
static new_from_entry(key: ScriptHash, value: MintAssets): Mint;
2443+
24372444
/**
24382445
* @returns {number}
24392446
*/
@@ -2456,6 +2463,18 @@ declare export class Mint {
24562463
* @returns {ScriptHashes}
24572464
*/
24582465
keys(): ScriptHashes;
2466+
2467+
/**
2468+
* Returns the multiasset where only positive (minting) entries are present
2469+
* @returns {MultiAsset}
2470+
*/
2471+
as_positive_multiasset(): MultiAsset;
2472+
2473+
/**
2474+
* Returns the multiasset where only negative (burning) entries are present
2475+
* @returns {MultiAsset}
2476+
*/
2477+
as_negative_multiasset(): MultiAsset;
24592478
}
24602479
/**
24612480
*/
@@ -2467,6 +2486,13 @@ declare export class MintAssets {
24672486
*/
24682487
static new(): MintAssets;
24692488

2489+
/**
2490+
* @param {AssetName} key
2491+
* @param {Int} value
2492+
* @returns {MintAssets}
2493+
*/
2494+
static new_from_entry(key: AssetName, value: Int): MintAssets;
2495+
24702496
/**
24712497
* @returns {number}
24722498
*/
@@ -5027,6 +5053,45 @@ declare export class TransactionBuilder {
50275053
): BigNum;
50285054

50295055
/**
5056+
* Add output by specifying the Address and Value
5057+
* @param {Address} address
5058+
* @param {Value} amount
5059+
*/
5060+
add_output_amount(address: Address, amount: Value): void;
5061+
5062+
/**
5063+
* Add output by specifying the Address and Coin (BigNum)
5064+
* Output will have no additional assets
5065+
* @param {Address} address
5066+
* @param {BigNum} coin
5067+
*/
5068+
add_output_coin(address: Address, coin: BigNum): void;
5069+
5070+
/**
5071+
* Add output by specifying the Address, the Coin (BigNum), and the MultiAsset
5072+
* @param {Address} address
5073+
* @param {BigNum} coin
5074+
* @param {MultiAsset} multiasset
5075+
*/
5076+
add_output_coin_and_asset(
5077+
address: Address,
5078+
coin: BigNum,
5079+
multiasset: MultiAsset
5080+
): void;
5081+
5082+
/**
5083+
* Add output by specifying the Address and the MultiAsset
5084+
* The output will be set to contain the minimum required amount of Coin
5085+
* @param {Address} address
5086+
* @param {MultiAsset} multiasset
5087+
*/
5088+
add_output_asset_and_min_required_coin(
5089+
address: Address,
5090+
multiasset: MultiAsset
5091+
): void;
5092+
5093+
/**
5094+
* Add explicit output via a TransactionOutput object
50305095
* @param {TransactionOutput} output
50315096
*/
50325097
add_output(output: TransactionOutput): void;
@@ -5064,11 +5129,123 @@ declare export class TransactionBuilder {
50645129
set_withdrawals(withdrawals: Withdrawals): void;
50655130

50665131
/**
5132+
* @returns {AuxiliaryData | void}
5133+
*/
5134+
get_auxiliary_data(): AuxiliaryData | void;
5135+
5136+
/**
5137+
* Set explicit auxiliary data via an AuxiliaryData object
5138+
* It might contain some metadata plus native or Plutus scripts
50675139
* @param {AuxiliaryData} auxiliary_data
50685140
*/
50695141
set_auxiliary_data(auxiliary_data: AuxiliaryData): void;
50705142

50715143
/**
5144+
* Set metadata using a GeneralTransactionMetadata object
5145+
* It will be set to the existing or new auxiliary data in this builder
5146+
* @param {GeneralTransactionMetadata} metadata
5147+
*/
5148+
set_metadata(metadata: GeneralTransactionMetadata): void;
5149+
5150+
/**
5151+
* Add a single metadatum using TransactionMetadatumLabel and TransactionMetadatum objects
5152+
* It will be securely added to existing or new metadata in this builder
5153+
* @param {BigNum} key
5154+
* @param {TransactionMetadatum} val
5155+
*/
5156+
add_metadatum(key: BigNum, val: TransactionMetadatum): void;
5157+
5158+
/**
5159+
* Add a single JSON metadatum using a TransactionMetadatumLabel and a String
5160+
* It will be securely added to existing or new metadata in this builder
5161+
* @param {BigNum} key
5162+
* @param {string} val
5163+
*/
5164+
add_json_metadatum(key: BigNum, val: string): void;
5165+
5166+
/**
5167+
* Add a single JSON metadatum using a TransactionMetadatumLabel, a String, and a MetadataJsonSchema object
5168+
* It will be securely added to existing or new metadata in this builder
5169+
* @param {BigNum} key
5170+
* @param {string} val
5171+
* @param {number} schema
5172+
*/
5173+
add_json_metadatum_with_schema(
5174+
key: BigNum,
5175+
val: string,
5176+
schema: number
5177+
): void;
5178+
5179+
/**
5180+
* Set explicit Mint object to this builder
5181+
* it will replace any previously existing mint
5182+
* @param {Mint} mint
5183+
*/
5184+
set_mint(mint: Mint): void;
5185+
5186+
/**
5187+
* Add a mint entry to this builder using a PolicyID and MintAssets object
5188+
* It will be securely added to existing or new Mint in this builder
5189+
* It will replace any existing mint assets with the same PolicyID
5190+
* @param {ScriptHash} policy_id
5191+
* @param {MintAssets} mint_assets
5192+
*/
5193+
set_mint_asset(policy_id: ScriptHash, mint_assets: MintAssets): void;
5194+
5195+
/**
5196+
* Add a mint entry to this builder using a PolicyID, AssetName, and Int object for amount
5197+
* It will be securely added to existing or new Mint in this builder
5198+
* It will replace any previous existing amount same PolicyID and AssetName
5199+
* @param {ScriptHash} policy_id
5200+
* @param {AssetName} asset_name
5201+
* @param {Int} amount
5202+
*/
5203+
add_mint_asset(
5204+
policy_id: ScriptHash,
5205+
asset_name: AssetName,
5206+
amount: Int
5207+
): void;
5208+
5209+
/**
5210+
* Add a mint entry together with an output to this builder
5211+
* Using a PolicyID, AssetName, Int for amount, Address, and Coin (BigNum) objects
5212+
* The asset will be securely added to existing or new Mint in this builder
5213+
* A new output will be added with the specified Address, the Coin value, and the minted asset
5214+
* @param {ScriptHash} policy_id
5215+
* @param {AssetName} asset_name
5216+
* @param {Int} amount
5217+
* @param {Address} address
5218+
* @param {BigNum} output_coin
5219+
*/
5220+
add_mint_asset_and_output(
5221+
policy_id: ScriptHash,
5222+
asset_name: AssetName,
5223+
amount: Int,
5224+
address: Address,
5225+
output_coin: BigNum
5226+
): void;
5227+
5228+
/**
5229+
* Add a mint entry together with an output to this builder
5230+
* Using a PolicyID, AssetName, Int for amount, and Address objects
5231+
* The asset will be securely added to existing or new Mint in this builder
5232+
* A new output will be added with the specified Address and the minted asset
5233+
* The output will be set to contain the minimum required amount of Coin
5234+
* @param {ScriptHash} policy_id
5235+
* @param {AssetName} asset_name
5236+
* @param {Int} amount
5237+
* @param {Address} address
5238+
*/
5239+
add_mint_asset_and_output_min_required_coin(
5240+
policy_id: ScriptHash,
5241+
asset_name: AssetName,
5242+
amount: Int,
5243+
address: Address
5244+
): void;
5245+
5246+
/**
5247+
* If set to true, add_change_if_needed will try
5248+
* to put pure Coin in a separate output from assets
50725249
* @param {boolean} prefer_pure_change
50735250
*/
50745251
set_prefer_pure_change(prefer_pure_change: boolean): void;
@@ -5121,6 +5298,9 @@ declare export class TransactionBuilder {
51215298

51225299
/**
51235300
* Warning: this function will mutate the /fee/ field
5301+
* Make sure to call this function last after setting all other tx-body properties
5302+
* Editing inputs, outputs, mint, etc. after change been calculated
5303+
* might cause a mismatch in calculated fee versus the required fee
51245304
* @param {Address} address
51255305
* @returns {boolean}
51265306
*/
@@ -5137,10 +5317,21 @@ declare export class TransactionBuilder {
51375317
output_sizes(): Uint32Array;
51385318

51395319
/**
5320+
* Returns object the body of the new transaction
5321+
* Auxiliary data itself is not included
5322+
* You can use `get_auxiliary_date` or `build_tx`
51405323
* @returns {TransactionBody}
51415324
*/
51425325
build(): TransactionBody;
51435326

5327+
/**
5328+
* Returns full Transaction object with the body and the auxiliary data
5329+
* NOTE: witness_set is set to just empty set
5330+
* NOTE: is_valid set to true
5331+
* @returns {Transaction}
5332+
*/
5333+
build_tx(): Transaction;
5334+
51445335
/**
51455336
* warning: sum of all parts of a transaction must equal 0. You cannot just set the fee to the min value and forget about it
51465337
* warning: min_fee may be slightly larger than the actual minimum fee (ex: a few lovelaces)
@@ -5827,6 +6018,12 @@ declare export class Value {
58276018
*/
58286019
static new(coin: BigNum): Value;
58296020

6021+
/**
6022+
* @param {MultiAsset} multiasset
6023+
* @returns {Value}
6024+
*/
6025+
static new_from_assets(multiasset: MultiAsset): Value;
6026+
58306027
/**
58316028
* @returns {Value}
58326029
*/

0 commit comments

Comments
 (0)