pha-deploy 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -8
- package/dist/actions/createSeries.d.ts.map +1 -1
- package/dist/actions/createSeries.js +2 -1
- package/dist/actions/createSeries.js.map +1 -1
- package/dist/actions/createToken.d.ts.map +1 -1
- package/dist/actions/createToken.js +2 -1
- package/dist/actions/createToken.js.map +1 -1
- package/dist/actions/mintFungibleToken.d.ts.map +1 -1
- package/dist/actions/mintFungibleToken.js +2 -1
- package/dist/actions/mintFungibleToken.js.map +1 -1
- package/dist/actions/mintNftToken.d.ts.map +1 -1
- package/dist/actions/mintNftToken.js +2 -1
- package/dist/actions/mintNftToken.js.map +1 -1
- package/dist/cli-contract.d.ts.map +1 -1
- package/dist/cli-contract.js +51 -2
- package/dist/cli-contract.js.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/contract/compiler.d.ts +2 -2
- package/dist/contract/compiler.d.ts.map +1 -1
- package/dist/contract/compiler.js +20 -3
- package/dist/contract/compiler.js.map +1 -1
- package/dist/contract/deploy.d.ts +4 -1
- package/dist/contract/deploy.d.ts.map +1 -1
- package/dist/contract/deploy.js +102 -31
- package/dist/contract/deploy.js.map +1 -1
- package/dist/rpc/txHash.d.ts +2 -0
- package/dist/rpc/txHash.d.ts.map +1 -0
- package/dist/rpc/txHash.js +34 -0
- package/dist/rpc/txHash.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,15 +12,16 @@ Current surface area:
|
|
|
12
12
|
- `contract compile`
|
|
13
13
|
- `contract deploy`
|
|
14
14
|
- `contract upgrade`
|
|
15
|
+
- `contract attach`
|
|
15
16
|
- `--version` prints both the `pha-deploy` version and the resolved `pha-tomb` version/path.
|
|
16
17
|
- Dry-run mode is available for token and contract transactions.
|
|
17
18
|
|
|
18
19
|
## Requirements
|
|
19
20
|
|
|
20
21
|
- Node.js `>=16`
|
|
21
|
-
- `pha-tomb >= 2.
|
|
22
|
+
- `pha-tomb >= 2.1.0` must be available for `contract compile`, either in `PATH` or through `--compiler` / `PHA_TOMB_PATH`
|
|
22
23
|
|
|
23
|
-
`contract deploy` and `contract
|
|
24
|
+
`contract deploy`, `contract upgrade`, and `contract attach` do not invoke the compiler directly. They work from a compiled artifact bundle or explicit `--script` / `--abi` inputs.
|
|
24
25
|
|
|
25
26
|
## Installation
|
|
26
27
|
|
|
@@ -40,15 +41,15 @@ node dist/cli.js --help
|
|
|
40
41
|
Example version output:
|
|
41
42
|
|
|
42
43
|
```text
|
|
43
|
-
pha-deploy 0.
|
|
44
|
-
pha-tomb version 2.
|
|
44
|
+
pha-deploy 0.5.0
|
|
45
|
+
pha-tomb version 2.1.0
|
|
45
46
|
pha-tomb path /usr/local/bin/pha-tomb
|
|
46
47
|
```
|
|
47
48
|
|
|
48
49
|
## Usage
|
|
49
50
|
|
|
50
51
|
```bash
|
|
51
|
-
pha-deploy contract <compile|deploy|upgrade> [options]
|
|
52
|
+
pha-deploy contract <compile|deploy|upgrade|attach> [options]
|
|
52
53
|
pha-deploy --create-token [options]
|
|
53
54
|
pha-deploy --create-series [options]
|
|
54
55
|
pha-deploy --mint-fungible [options]
|
|
@@ -120,11 +121,12 @@ Required token inputs by action:
|
|
|
120
121
|
|
|
121
122
|
### 1. Compile
|
|
122
123
|
|
|
123
|
-
Compile a `.tomb` source file through
|
|
124
|
+
Compile a `.tomb` source file through `pha-tomb` from `PATH`, or pin an exact local compiler with `--compiler` / `PHA_TOMB_PATH`.
|
|
124
125
|
|
|
125
126
|
```bash
|
|
126
127
|
pha-deploy contract compile \
|
|
127
128
|
--source ./contracts/demo.tomb \
|
|
129
|
+
--compiler /path/to/pha-tomb \
|
|
128
130
|
--out ./dist/contracts/demo \
|
|
129
131
|
--debug \
|
|
130
132
|
--protocol 16 \
|
|
@@ -134,6 +136,7 @@ pha-deploy contract compile \
|
|
|
134
136
|
Supported compile flags:
|
|
135
137
|
|
|
136
138
|
- `--source <path>`: required `.tomb` source file
|
|
139
|
+
- `--compiler <path>`: optional explicit `pha-tomb` executable path; takes precedence over `PHA_TOMB_PATH` and `PATH`
|
|
137
140
|
- `--out <dir>`: final artifact bundle directory
|
|
138
141
|
- `--contract-name <name>`: required when the compiler emits multiple modules and you need to pick one
|
|
139
142
|
- `--protocol <number>`: passed through to `pha-tomb`
|
|
@@ -141,6 +144,8 @@ Supported compile flags:
|
|
|
141
144
|
- `--nativecheck <off|warn|error>`
|
|
142
145
|
- `--libpath <path>`: repeatable additional library search path
|
|
143
146
|
|
|
147
|
+
`PHA_TOMB_PATH=/path/to/pha-tomb` is also supported when `--compiler` is omitted and you want to avoid whichever `pha-tomb` happens to be first in `PATH`.
|
|
148
|
+
|
|
144
149
|
Compile output:
|
|
145
150
|
|
|
146
151
|
- prints the exact compiler command and cwd
|
|
@@ -155,7 +160,7 @@ Compile output:
|
|
|
155
160
|
- optional `<contract>.pvm.hex`
|
|
156
161
|
- optional `<contract>.abi.hex`
|
|
157
162
|
|
|
158
|
-
`manifest.json` is the preferred handoff format for later deploy/upgrade commands.
|
|
163
|
+
`manifest.json` is the preferred handoff format for later deploy/upgrade/attach commands.
|
|
159
164
|
|
|
160
165
|
### 2. Deploy
|
|
161
166
|
|
|
@@ -199,7 +204,24 @@ pha-deploy contract upgrade \
|
|
|
199
204
|
--dry-run
|
|
200
205
|
```
|
|
201
206
|
|
|
202
|
-
|
|
207
|
+
### 4. Attach
|
|
208
|
+
|
|
209
|
+
Attach a compiled VM contract bundle to an already existing token symbol:
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
pha-deploy contract attach \
|
|
213
|
+
--rpc https://testnet.phantasma.info/rpc \
|
|
214
|
+
--nexus testnet \
|
|
215
|
+
--chain main \
|
|
216
|
+
--wif <WIF> \
|
|
217
|
+
--manifest ./dist/contracts/demo/manifest.json \
|
|
218
|
+
--symbol DEMO \
|
|
219
|
+
--dry-run
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
When `--symbol` is omitted, `contract attach` defaults to the bundle contract name from the manifest or direct artifact inputs.
|
|
223
|
+
|
|
224
|
+
Shared deploy/upgrade/attach flags:
|
|
203
225
|
|
|
204
226
|
- `--rpc <url>`: required
|
|
205
227
|
- `--nexus <name>`: required
|
|
@@ -216,6 +238,10 @@ Shared deploy/upgrade flags:
|
|
|
216
238
|
- `--payload-hex <hex>`
|
|
217
239
|
- `--dry-run`
|
|
218
240
|
|
|
241
|
+
Attach-only flag:
|
|
242
|
+
|
|
243
|
+
- `--symbol <symbol>`: existing token symbol to attach to; defaults to the bundle contract name when omitted
|
|
244
|
+
|
|
219
245
|
Deploy/upgrade output always includes:
|
|
220
246
|
|
|
221
247
|
- operation
|
|
@@ -226,6 +252,8 @@ Deploy/upgrade output always includes:
|
|
|
226
252
|
- generated VM script hex
|
|
227
253
|
- signed transaction hex
|
|
228
254
|
|
|
255
|
+
Attach output also prints the resolved token symbol used for the interop call.
|
|
256
|
+
|
|
229
257
|
When `--dry-run` is omitted, the CLI also broadcasts the transaction, waits for the tx result, and prints the tx hash.
|
|
230
258
|
|
|
231
259
|
## Quick Examples
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSeries.d.ts","sourceRoot":"","sources":["../../src/actions/createSeries.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EAKb,cAAc,EAGf,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"createSeries.d.ts","sourceRoot":"","sources":["../../src/actions/createSeries.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,EAKb,cAAc,EAGf,MAAM,kBAAkB,CAAC;AAK1B,qBAAa,eAAe;IAEjB,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,aAAa,EAAE,MAAM;IACrB,UAAU,EAAE,MAAM;IAClB,uBAAuB,EAAE,MAAM;IAC/B,gBAAgB,EAAE,MAAM;IACxB,mBAAmB,EAAE,MAAM;IAC3B,YAAY,EAAE,cAAc;IAC5B,cAAc,EAAE,aAAa,EAAE;gBAT/B,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,UAAU,EAAE,MAAM,EAClB,uBAAuB,EAAE,MAAM,EAC/B,gBAAgB,EAAE,MAAM,EACxB,mBAAmB,EAAE,MAAM,EAC3B,YAAY,EAAE,cAAc,EAC5B,cAAc,EAAE,aAAa,EAAE;IAcxC,WAAW;;;;CAWZ;AAID,wBAAsB,YAAY,CAChC,GAAG,EAAE,eAAe,EACpB,MAAM,EAAE,OAAO,EACf,WAAW,GAAE,OAAe,iBA+D7B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createSeriesCfg = void 0;
|
|
4
4
|
exports.createSeries = createSeries;
|
|
5
5
|
const phantasma_sdk_ts_1 = require("phantasma-sdk-ts");
|
|
6
|
+
const txHash_1 = require("../rpc/txHash");
|
|
6
7
|
const waitForTx_1 = require("./waitForTx");
|
|
7
8
|
const helpers_1 = require("./helpers");
|
|
8
9
|
class createSeriesCfg {
|
|
@@ -67,7 +68,7 @@ async function createSeries(cfg, dryRun, logSettings = false) {
|
|
|
67
68
|
}
|
|
68
69
|
console.log("Broadcasting transaction...");
|
|
69
70
|
const rpc = new phantasma_sdk_ts_1.PhantasmaAPI(cfg.rpc, null, cfg.nexus);
|
|
70
|
-
|
|
71
|
+
const txHash = (0, txHash_1.requireRpcTxHash)(await rpc.sendCarbonTransaction(tx), "create-series transaction");
|
|
71
72
|
console.log("txHash: ", txHash);
|
|
72
73
|
const { success, result } = await (0, waitForTx_1.waitForTx)(rpc, txHash);
|
|
73
74
|
if (success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSeries.js","sourceRoot":"","sources":["../../src/actions/createSeries.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createSeries.js","sourceRoot":"","sources":["../../src/actions/createSeries.ts"],"names":[],"mappings":";;;AA0DA,oCAkEC;AA5HD,uDAa0B;AAC1B,0CAAiD;AACjD,2CAAwC;AACxC,uCAAmE;AAEnE,MAAa,eAAe;IAEjB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAVT,YACS,GAAW,EACX,KAAa,EACb,GAAW,EACX,aAAqB,EACrB,UAAkB,EAClB,uBAA+B,EAC/B,gBAAwB,EACxB,mBAA2B,EAC3B,YAA4B,EAC5B,cAA+B;QAT/B,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QACb,QAAG,GAAH,GAAG,CAAQ;QACX,kBAAa,GAAb,aAAa,CAAQ;QACrB,eAAU,GAAV,UAAU,CAAQ;QAClB,4BAAuB,GAAvB,uBAAuB,CAAQ;QAC/B,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,wBAAmB,GAAnB,mBAAmB,CAAQ;QAC3B,iBAAY,GAAZ,YAAY,CAAgB;QAC5B,mBAAc,GAAd,cAAc,CAAiB;QAEtC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;IAED,WAAW;QACT,gCAAgC;QAChC,MAAM,EAAE,GAAG,EAAE,KAA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AAC,GAAG,CAAC,qCAAqC,EAAE,EAAE,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,IAAA,sBAAY,EAAC,6BAAU,CAAC,YAAY,CAAC,8BAAW,EAAE,IAAA,6BAAU,EAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACnF,OAAO;IACT,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;IAE3C,MAAM,GAAG,GAAG,IAAI,+BAAY,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;IAEvD,MAAM,MAAM,GAAG,IAAA,yBAAgB,EAC7B,MAAM,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC,EACnC,2BAA2B,CAC5B,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAEhC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,qBAAS,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEzD,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,QAAQ,GAAG,4CAAyB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAC7D,OAAO,CAAC,GAAG,CACT,qCAAqC,oBAAoB,CAAC,QAAQ,EAAE,yBAAyB,QAAQ,EAAE,CACxG,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACzC,CAAC;AACH,CAAC","sourcesContent":["import {\n Bytes32,\n CarbonBlob,\n CreateSeriesFeeOptions,\n CreateTokenSeriesTxHelper,\n MetadataField,\n PhantasmaAPI,\n PhantasmaKeys,\n SeriesInfoBuilder,\n SignedTxMsg,\n VmStructSchema,\n getRandomPhantasmaId,\n hexToBytes,\n} from \"phantasma-sdk-ts\";\nimport { requireRpcTxHash } from \"../rpc/txHash\";\nimport { waitForTx } from \"./waitForTx\";\nimport { bigintReplacer, Metadata, formatForLog } from \"./helpers\";\n\nexport class createSeriesCfg {\n constructor(\n public rpc: string,\n public nexus: string,\n public wif: string,\n public carbonTokenId: bigint,\n public gasFeeBase: bigint,\n public gasFeeCreateTokenSeries: bigint,\n public gasFeeMultiplier: bigint,\n public createSeriesMaxData: bigint,\n public seriesSchema: VmStructSchema,\n public seriesMetadata: MetadataField[]\n ) {\n this.rpc = rpc;\n this.nexus = nexus;\n this.wif = wif;\n this.carbonTokenId = carbonTokenId;\n this.gasFeeBase = gasFeeBase;\n this.gasFeeCreateTokenSeries = gasFeeCreateTokenSeries;\n this.gasFeeMultiplier = gasFeeMultiplier;\n this.createSeriesMaxData = createSeriesMaxData;\n this.seriesSchema = seriesSchema;\n this.seriesMetadata = seriesMetadata;\n }\n\n toPrintable() {\n // Do not leak WIF; derive owner\n const { wif: _omit, seriesMetadata: seriesMetadata, ...rest } = this; // rest has all public fields except wif/sharedRom\n const owner = PhantasmaKeys.fromWIF(this.wif).Address.toString();\n\n return {\n ...rest,\n owner,\n seriesMetadata\n };\n }\n}\n\n\n\nexport async function createSeries(\n cfg: createSeriesCfg,\n dryRun: boolean,\n logSettings: boolean = false,\n) {\n const txSender = PhantasmaKeys.fromWIF(cfg.wif);\n const senderPubKey = new Bytes32(txSender.PublicKey);\n\n const newPhantasmaSeriesId = await getRandomPhantasmaId();\n\n if (logSettings) {\n console.log(\n `Creating new series '${newPhantasmaSeriesId}' using these settings:`,\n JSON.stringify(cfg.toPrintable(), bigintReplacer, 2),\n );\n }\n\n const info = SeriesInfoBuilder.build(\n cfg.seriesSchema,\n newPhantasmaSeriesId,\n 0,\n 0,\n senderPubKey,\n cfg.seriesMetadata\n );\n\n const feeOptions = new CreateSeriesFeeOptions(\n cfg.gasFeeBase,\n cfg.gasFeeCreateTokenSeries,\n cfg.gasFeeMultiplier,\n );\n\n const tx = CreateTokenSeriesTxHelper.buildTxAndSignHex(\n cfg.carbonTokenId,\n info,\n txSender,\n feeOptions,\n cfg.createSeriesMaxData,\n );\n\n if (dryRun) {\n console.log(`[dry-run] Prepared tx (not sent): ${tx}`);\n console.log(formatForLog(CarbonBlob.NewFromBytes(SignedTxMsg, hexToBytes(tx), 0)));\n return;\n }\n\n console.log(\"Broadcasting transaction...\");\n\n const rpc = new PhantasmaAPI(cfg.rpc, null, cfg.nexus);\n\n const txHash = requireRpcTxHash(\n await rpc.sendCarbonTransaction(tx),\n \"create-series transaction\",\n );\n console.log(\"txHash: \", txHash);\n\n const { success, result } = await waitForTx(rpc, txHash);\n\n if (success) {\n var seriesId = CreateTokenSeriesTxHelper.parseResult(result);\n console.log(\n `Deployed series with phantasma ID ${newPhantasmaSeriesId.toString()} and carbon series ID ${seriesId}`,\n );\n } else {\n console.log(\"Could not deploy series\");\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createToken.d.ts","sourceRoot":"","sources":["../../src/actions/createToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"createToken.d.ts","sourceRoot":"","sources":["../../src/actions/createToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAYL,YAAY,EACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAkB,QAAQ,EAAgB,MAAM,WAAW,CAAC;AAEnE,qBAAa,cAAc;IAEhB,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,MAAM;IAClB,qBAAqB,EAAE,MAAM;IAC7B,uBAAuB,EAAE,MAAM;IAC/B,gBAAgB,EAAE,MAAM;IACxB,kBAAkB,EAAE,MAAM;IAC1B,YAAY,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS;IAC7C,mBAAmB,EAAE,QAAQ;IAC7B,SAAS,EAAE,SAAS;IACpB,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IACzC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;gBAb3C,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,qBAAqB,EAAE,MAAM,EAC7B,uBAAuB,EAAE,MAAM,EAC/B,gBAAgB,EAAE,MAAM,EACxB,kBAAkB,EAAE,MAAM,EAC1B,YAAY,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,EAC7C,mBAAmB,EAAE,QAAQ,EAC7B,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAkBpD,WAAW;;;CAUZ;AAED,wBAAsB,WAAW,CAC/B,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,OAAO,EACf,WAAW,GAAE,OAAe,iBAoG7B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTokenCfg = void 0;
|
|
4
4
|
exports.createToken = createToken;
|
|
5
5
|
const phantasma_sdk_ts_1 = require("phantasma-sdk-ts");
|
|
6
|
+
const txHash_1 = require("../rpc/txHash");
|
|
6
7
|
const waitForTx_1 = require("./waitForTx");
|
|
7
8
|
const helpers_1 = require("./helpers");
|
|
8
9
|
class createTokenCfg {
|
|
@@ -112,7 +113,7 @@ async function createToken(cfg, dryRun, logSettings = false) {
|
|
|
112
113
|
}
|
|
113
114
|
console.log("Broadcasting transaction...");
|
|
114
115
|
const rpc = new phantasma_sdk_ts_1.PhantasmaAPI(cfg.rpc, null, cfg.nexus);
|
|
115
|
-
|
|
116
|
+
const txHash = (0, txHash_1.requireRpcTxHash)(await rpc.sendCarbonTransaction(tx), "create-token transaction");
|
|
116
117
|
console.log("txHash: ", txHash);
|
|
117
118
|
const { success, result } = await (0, waitForTx_1.waitForTx)(rpc, txHash);
|
|
118
119
|
if (success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createToken.js","sourceRoot":"","sources":["../../src/actions/createToken.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createToken.js","sourceRoot":"","sources":["../../src/actions/createToken.ts"],"names":[],"mappings":";;;AAgEA,kCAuGC;AAvKD,uDAa0B;AAE1B,0CAAiD;AACjD,2CAAwC;AACxC,uCAAmE;AAEnE,MAAa,cAAc;IAEhB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAdT,YACS,GAAW,EACX,KAAa,EACb,GAAW,EACX,MAAc,EACd,UAAkB,EAClB,qBAA6B,EAC7B,uBAA+B,EAC/B,gBAAwB,EACxB,kBAA0B,EAC1B,YAA6C,EAC7C,mBAA6B,EAC7B,SAAoB,EACpB,cAAyC,EACzC,gBAA2C;QAb3C,QAAG,GAAH,GAAG,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QACb,QAAG,GAAH,GAAG,CAAQ;QACX,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,0BAAqB,GAArB,qBAAqB,CAAQ;QAC7B,4BAAuB,GAAvB,uBAAuB,CAAQ;QAC/B,qBAAgB,GAAhB,gBAAgB,CAAQ;QACxB,uBAAkB,GAAlB,kBAAkB,CAAQ;QAC1B,iBAAY,GAAZ,YAAY,CAAiC;QAC7C,wBAAmB,GAAnB,mBAAmB,CAAU;QAC7B,cAAS,GAAT,SAAS,CAAW;QACpB,mBAAc,GAAd,cAAc,CAA2B;QACzC,qBAAgB,GAAhB,gBAAgB,CAA2B;QAElD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB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AAC,EAAE,CAAC,EACnC,0BAA0B,CAC3B,CAAC;IACF,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAEhC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAA,qBAAS,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEzD,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,OAAO,GAAG,sCAAmB,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,2BAA2B,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IACxC,CAAC;AACH,CAAC","sourcesContent":["import {\n Bytes32,\n CarbonBlob,\n CreateTokenFeeOptions,\n CreateTokenTxHelper,\n hexToBytes,\n IntX,\n SignedTxMsg,\n PhantasmaAPI,\n PhantasmaKeys,\n TokenInfoBuilder,\n TokenMetadataBuilder,\n TokenSchemas,\n} from \"phantasma-sdk-ts\";\nimport { TokenType } from \"../config\";\nimport { requireRpcTxHash } from \"../rpc/txHash\";\nimport { waitForTx } from \"./waitForTx\";\nimport { bigintReplacer, Metadata, formatForLog } from \"./helpers\";\n\nexport class createTokenCfg {\n constructor(\n public rpc: string,\n public nexus: string,\n public wif: string,\n public symbol: string,\n public gasFeeBase: bigint,\n public gasFeeCreateTokenBase: bigint,\n public gasFeeCreateTokenSymbol: bigint,\n public gasFeeMultiplier: bigint,\n public createTokenMaxData: bigint,\n public tokenSchemas: TokenSchemas | null | undefined,\n public tokenMetadataFields: Metadata,\n public tokenType: TokenType,\n public tokenMaxSupply: bigint | null | undefined,\n public fungibleDecimals: number | null | undefined,\n ) {\n this.rpc = rpc;\n this.nexus = nexus;\n this.wif = wif;\n this.symbol = symbol;\n this.gasFeeBase = gasFeeBase;\n this.gasFeeCreateTokenBase = gasFeeCreateTokenBase;\n this.gasFeeCreateTokenSymbol = gasFeeCreateTokenSymbol;\n this.gasFeeMultiplier = gasFeeMultiplier;\n this.createTokenMaxData = createTokenMaxData;\n this.tokenSchemas = tokenSchemas;\n this.tokenMetadataFields = tokenMetadataFields;\n this.tokenType = tokenType;\n this.tokenMaxSupply = tokenMaxSupply;\n this.fungibleDecimals = fungibleDecimals;\n }\n\n toPrintable() {\n // Do not leak WIF; derive owner\n const { wif: _omit, ...rest } = this; // rest has all public fields except wif\n const owner = PhantasmaKeys.fromWIF(this.wif).Address.toString();\n\n return {\n ...rest,\n owner,\n };\n }\n}\n\nexport async function createToken(\n cfg: createTokenCfg,\n dryRun: boolean,\n logSettings: boolean = false,\n) {\n const txSender = PhantasmaKeys.fromWIF(cfg.wif);\n const senderPubKey = new Bytes32(txSender.PublicKey);\n\n if (logSettings) {\n console.log(\n \"Deploying new token using these settings:\",\n JSON.stringify(cfg.toPrintable(), bigintReplacer, 2),\n );\n }\n\n if (cfg.tokenMetadataFields == null) {\n throw Error('Token metadata is mandatory');\n }\n\n const tokenType = cfg.tokenType === \"fungible\" ? \"fungible\" : \"nft\";\n const isFungible = tokenType === \"fungible\";\n\n let maxSupply: IntX;\n let decimals = 0;\n\n if (isFungible) {\n if (cfg.tokenMaxSupply == null) {\n throw Error(\"token_max_supply is required for fungible tokens\");\n }\n if (cfg.fungibleDecimals == null) {\n throw Error(\"fungible_decimals is required for fungible tokens\");\n }\n if (!Number.isInteger(cfg.fungibleDecimals) || cfg.fungibleDecimals < 0) {\n throw Error(\"fungible_decimals must be a non-negative integer\");\n }\n if (cfg.fungibleDecimals > 255) {\n throw Error(\"fungible_decimals must be <= 255\");\n }\n }\n\n const maxSupplyValue =\n cfg.tokenMaxSupply != null ? cfg.tokenMaxSupply : 0n;\n if (maxSupplyValue < 0n) {\n throw Error(\"token_max_supply must be non-negative\");\n }\n if (isFungible) {\n decimals = cfg.fungibleDecimals!;\n maxSupply = IntX.fromBigInt(maxSupplyValue);\n } else {\n maxSupply =\n maxSupplyValue === 0n\n ? IntX.fromI64(0n)\n : IntX.fromBigInt(maxSupplyValue);\n }\n\n const info = TokenInfoBuilder.build(\n cfg.symbol,\n maxSupply,\n !isFungible,\n decimals,\n senderPubKey,\n TokenMetadataBuilder.buildAndSerialize(cfg.tokenMetadataFields.fields),\n cfg.tokenSchemas\n );\n\n const feeOptions = new CreateTokenFeeOptions(\n cfg.gasFeeBase,\n cfg.gasFeeCreateTokenBase,\n cfg.gasFeeCreateTokenSymbol,\n cfg.gasFeeMultiplier,\n );\n\n const tx = CreateTokenTxHelper.buildTxAndSignHex(\n info,\n txSender,\n feeOptions,\n cfg.createTokenMaxData,\n );\n\n if (dryRun) {\n console.log(`[dry-run] Prepared tx (not sent): ${tx}`);\n console.log(formatForLog(CarbonBlob.NewFromBytes(SignedTxMsg, hexToBytes(tx), 0)));\n return;\n }\n\n console.log(\"Broadcasting transaction...\");\n\n const rpc = new PhantasmaAPI(cfg.rpc, null, cfg.nexus);\n\n const txHash = requireRpcTxHash(\n await rpc.sendCarbonTransaction(tx),\n \"create-token transaction\",\n );\n console.log(\"txHash: \", txHash);\n\n const { success, result } = await waitForTx(rpc, txHash);\n\n if (success) {\n var tokenId = CreateTokenTxHelper.parseResult(result);\n console.log(\"Deployed carbon token ID:\", tokenId);\n } else {\n console.log(\"Could not deploy token\");\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mintFungibleToken.d.ts","sourceRoot":"","sources":["../../src/actions/mintFungibleToken.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mintFungibleToken.d.ts","sourceRoot":"","sources":["../../src/actions/mintFungibleToken.ts"],"names":[],"mappings":"AAsBA,qBAAa,oBAAoB;IAEtB,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,aAAa,EAAE,MAAM;IACrB,EAAE,EAAE,MAAM;IACV,MAAM,EAAE,MAAM;IACd,UAAU,EAAE,MAAM;IAClB,gBAAgB,EAAE,MAAM;IACxB,gBAAgB,EAAE,MAAM;gBARxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,EAAE,EAAE,MAAM,EACV,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM;IAajC,WAAW;;;CAUZ;AAED,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,oBAAoB,EACzB,MAAM,EAAE,OAAO,EACf,WAAW,GAAE,OAAe,iBA8E7B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mintFungibleTokenCfg = void 0;
|
|
4
4
|
exports.mintFungibleToken = mintFungibleToken;
|
|
5
5
|
const phantasma_sdk_ts_1 = require("phantasma-sdk-ts");
|
|
6
|
+
const txHash_1 = require("../rpc/txHash");
|
|
6
7
|
const waitForTx_1 = require("./waitForTx");
|
|
7
8
|
const helpers_1 = require("./helpers");
|
|
8
9
|
class mintFungibleTokenCfg {
|
|
@@ -83,7 +84,7 @@ async function mintFungibleToken(cfg, dryRun, logSettings = false) {
|
|
|
83
84
|
}
|
|
84
85
|
console.log("Broadcasting transaction...");
|
|
85
86
|
const rpc = new phantasma_sdk_ts_1.PhantasmaAPI(cfg.rpc, null, cfg.nexus);
|
|
86
|
-
const txHash = await rpc.sendCarbonTransaction(txHex);
|
|
87
|
+
const txHash = (0, txHash_1.requireRpcTxHash)(await rpc.sendCarbonTransaction(txHex), "mint-fungible transaction");
|
|
87
88
|
console.log("txHash: ", txHash);
|
|
88
89
|
const { success, result } = await (0, waitForTx_1.waitForTx)(rpc, txHash);
|
|
89
90
|
if (!success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mintFungibleToken.js","sourceRoot":"","sources":["../../src/actions/mintFungibleToken.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3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qBAAS,EAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAEzD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IAED,IAAI,CAAC;QACH,MAAM,CAAC,GAAG,IAAI,qCAAkB,CAAC,IAAA,6BAAU,EAAC,MAAM,CAAC,CAAC,CAAC;QACrD,MAAM,UAAU,GAAG,uBAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAC3C,OAAO,CAAC,GAAG,CAAC,yBAAyB,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CACT,iEAAiE,EACjE,MAAM,CACP,CAAC;QACF,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACjF,CAAC;AACH,CAAC","sourcesContent":["import {\n Address,\n Bytes32,\n CarbonBinaryReader,\n CarbonBlob,\n FeeOptions,\n hexToBytes,\n IntX,\n PhantasmaAPI,\n PhantasmaKeys,\n SignedTxMsg,\n SmallString,\n TxMsg,\n TxMsgMintFungible,\n TxMsgSigner,\n TxTypes,\n bytesToHex,\n} from \"phantasma-sdk-ts\";\nimport { requireRpcTxHash } from \"../rpc/txHash\";\nimport { waitForTx } from \"./waitForTx\";\nimport { bigintReplacer, formatForLog } from \"./helpers\";\n\nexport class mintFungibleTokenCfg {\n constructor(\n public rpc: string,\n public nexus: string,\n public wif: string,\n public carbonTokenId: bigint,\n public to: string,\n public amount: bigint,\n public gasFeeBase: bigint,\n public gasFeeMultiplier: bigint,\n public mintTokenMaxData: bigint,\n ) {\n this.rpc = rpc;\n this.nexus = nexus;\n this.wif = wif;\n this.carbonTokenId = carbonTokenId;\n this.to = to;\n this.amount = amount;\n this.gasFeeBase = gasFeeBase;\n this.gasFeeMultiplier = gasFeeMultiplier;\n this.mintTokenMaxData = mintTokenMaxData;\n }\n\n toPrintable() {\n // Do not leak WIF; derive owner address.\n const { wif: _omit, ...rest } = this;\n const owner = PhantasmaKeys.fromWIF(this.wif).Address.toString();\n\n return {\n ...rest,\n owner,\n };\n }\n}\n\nexport async function mintFungibleToken(\n cfg: mintFungibleTokenCfg,\n dryRun: boolean,\n logSettings: boolean = false,\n) {\n if (cfg.amount <= 0n) {\n throw new Error(\"mint_fungible_amount must be a positive integer\");\n }\n\n const txSender = PhantasmaKeys.fromWIF(cfg.wif);\n const senderPubKey = new Bytes32(txSender.PublicKey);\n\n const toAddr = Address.Parse(cfg.to);\n const receiverPubKey = new Bytes32(toAddr.GetPublicKey());\n\n if (logSettings) {\n console.log(\n \"Minting fungible tokens using these settings:\",\n JSON.stringify(cfg.toPrintable(), bigintReplacer, 2),\n );\n }\n\n // There is no dedicated MintFungible TxHelper in `phantasma-sdk-ts` yet, so we build the\n // Carbon TxMsg manually using the SDK core types. TokenContract::MintFungible returns the\n // receiver's new balance after minting, encoded as IntX in the tx result.\n const feeOptions = new FeeOptions(cfg.gasFeeBase, cfg.gasFeeMultiplier);\n const maxGas = feeOptions.calculateMaxGas();\n\n const msg = new TxMsg();\n msg.type = TxTypes.MintFungible;\n msg.expiry = BigInt(Date.now() + 60_000); // 60s from now (same pattern as other tx helpers)\n msg.maxGas = maxGas;\n msg.maxData = cfg.mintTokenMaxData;\n msg.gasFrom = senderPubKey;\n msg.payload = SmallString.empty;\n\n const mint = new TxMsgMintFungible();\n mint.tokenId = cfg.carbonTokenId;\n mint.to = receiverPubKey;\n mint.amount = IntX.fromBigInt(cfg.amount);\n msg.msg = mint;\n\n const txBytes = TxMsgSigner.signAndSerialize(msg, txSender);\n const txHex = bytesToHex(txBytes);\n\n if (dryRun) {\n console.log(`[dry-run] Prepared tx (not sent): ${txHex}`);\n console.log(\n formatForLog(CarbonBlob.NewFromBytes(SignedTxMsg, hexToBytes(txHex), 0)),\n );\n return;\n }\n\n console.log(\"Broadcasting transaction...\");\n\n const rpc = new PhantasmaAPI(cfg.rpc, null, cfg.nexus);\n\n const txHash = requireRpcTxHash(\n await rpc.sendCarbonTransaction(txHex),\n \"mint-fungible transaction\",\n );\n console.log(\"txHash: \", txHash);\n\n const { success, result } = await waitForTx(rpc, txHash);\n\n if (!success) {\n console.log(\"Could not mint fungible tokens\");\n return;\n }\n\n try {\n const r = new CarbonBinaryReader(hexToBytes(result));\n const newBalance = IntX.read(r).toBigInt();\n console.log(\"New balance after mint:\", newBalance.toString());\n } catch (err) {\n console.log(\n \"Mint succeeded but could not decode result as IntX; raw result:\",\n result,\n );\n console.log(\"Decode error:\", err instanceof Error ? err.message : String(err));\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mintNftToken.d.ts","sourceRoot":"","sources":["../../src/actions/mintNftToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,cAAc,EACd,aAAa,EACd,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"mintNftToken.d.ts","sourceRoot":"","sources":["../../src/actions/mintNftToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAWL,cAAc,EACd,aAAa,EACd,MAAM,kBAAkB,CAAC;AAmB1B,qBAAa,eAAe;IAEjB,GAAG,EAAE,MAAM;IACX,KAAK,EAAE,MAAM;IACb,GAAG,EAAE,MAAM;IACX,aAAa,EAAE,MAAM;IACrB,iBAAiB,EAAE,MAAM;IACzB,YAAY,EAAE,cAAc;IAC5B,WAAW,EAAE,aAAa,EAAE;IAC5B,UAAU,EAAE,MAAM;IAClB,gBAAgB,EAAE,MAAM;IACxB,gBAAgB,EAAE,MAAM;gBATxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,aAAa,EAAE,MAAM,EACrB,iBAAiB,EAAE,MAAM,EACzB,YAAY,EAAE,cAAc,EAC5B,WAAW,EAAE,aAAa,EAAE,EAC5B,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,gBAAgB,EAAE,MAAM;IAcjC,WAAW;;;;CAYZ;AAED,wBAAsB,YAAY,CAChC,GAAG,EAAE,eAAe,EACpB,MAAM,EAAE,OAAO,EACf,WAAW,GAAE,OAAe,iBAqE7B"}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mintNftTokenCfg = void 0;
|
|
4
4
|
exports.mintNftToken = mintNftToken;
|
|
5
5
|
const phantasma_sdk_ts_1 = require("phantasma-sdk-ts");
|
|
6
|
+
const txHash_1 = require("../rpc/txHash");
|
|
6
7
|
const waitForTx_1 = require("./waitForTx");
|
|
7
8
|
const helpers_1 = require("./helpers");
|
|
8
9
|
function bytes32HexToRpcDecimal(hex) {
|
|
@@ -77,7 +78,7 @@ async function mintNftToken(cfg, dryRun, logSettings = false) {
|
|
|
77
78
|
}
|
|
78
79
|
console.log("Broadcasting transaction...");
|
|
79
80
|
const rpc = new phantasma_sdk_ts_1.PhantasmaAPI(cfg.rpc, null, cfg.nexus);
|
|
80
|
-
|
|
81
|
+
const txHash = (0, txHash_1.requireRpcTxHash)(await rpc.sendCarbonTransaction(tx), "mint-nft transaction");
|
|
81
82
|
console.log("txHash: ", txHash);
|
|
82
83
|
const { success, result } = await (0, waitForTx_1.waitForTx)(rpc, txHash);
|
|
83
84
|
if (success) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mintNftToken.js","sourceRoot":"","sources":["../../src/actions/mintNftToken.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"mintNftToken.js","sourceRoot":"","sources":["../../src/actions/mintNftToken.ts"],"names":[],"mappings":";;;AAuEA,oCAwEC;AA/ID,uDAa0B;AAC1B,0CAAiD;AACjD,2CAAwC;AACxC,uCAAyD;AAE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BAAuB,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QACtE,MAAM,oBAAoB,GAAG,sBAAsB,CAAC,uBAAuB,CAAC,CAAC;QAC7E,OAAO,CAAC,GAAG,CACT,gCAAgC,oBAAoB,OAAO,uBAAuB,4BAA4B,gBAAgB,CAAC,KAAK,EAAE,EAAE,CACzI,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IACpC,CAAC;AACH,CAAC","sourcesContent":["import {\n Bytes32,\n CarbonBlob,\n hexToBytes,\n MintNftFeeOptions,\n MintPhantasmaNonFungibleTxHelper,\n PhantasmaAPI,\n PhantasmaNftRomBuilder,\n PhantasmaKeys,\n SignedTxMsg,\n TokenHelper,\n VmStructSchema,\n MetadataField,\n} from \"phantasma-sdk-ts\";\nimport { requireRpcTxHash } from \"../rpc/txHash\";\nimport { waitForTx } from \"./waitForTx\";\nimport { bigintReplacer, formatForLog } from \"./helpers\";\n\nfunction bytes32HexToRpcDecimal(hex: string): string {\n if (hex.length === 0) {\n return \"0\";\n }\n\n // RPC/public read paths interpret the raw Bytes32 `_i` word as an unsigned little-endian integer.\n const littleEndianHex = Array.from(hexToBytes(hex))\n .reverse()\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n\n return BigInt(`0x${littleEndianHex}`).toString();\n}\n\nexport class mintNftTokenCfg {\n constructor(\n public rpc: string,\n public nexus: string,\n public wif: string,\n public carbonTokenId: bigint,\n public phantasmaSeriesId: bigint,\n public nftRomSchema: VmStructSchema,\n public nftMetadata: MetadataField[],\n public gasFeeBase: bigint,\n public gasFeeMultiplier: bigint,\n public mintTokenMaxData: bigint,\n ) {\n this.rpc = rpc;\n this.nexus = nexus;\n this.wif = wif;\n this.carbonTokenId = carbonTokenId;\n this.phantasmaSeriesId = phantasmaSeriesId;\n this.nftRomSchema = nftRomSchema;\n this.nftMetadata = nftMetadata;\n this.gasFeeBase = gasFeeBase;\n this.gasFeeMultiplier = gasFeeMultiplier;\n this.mintTokenMaxData = mintTokenMaxData;\n }\n\n toPrintable() {\n // Do not leak WIF; derive owner\n const { wif: _omit, nftMetadata, ...rest } =\n this; // rest has all public fields except wif/metadata strings\n const owner = PhantasmaKeys.fromWIF(this.wif).Address.toString();\n\n return {\n ...rest,\n owner,\n nftMetadata\n };\n }\n}\n\nexport async function mintNftToken(\n cfg: mintNftTokenCfg,\n dryRun: boolean,\n logSettings: boolean = false,\n) {\n const txSender = PhantasmaKeys.fromWIF(cfg.wif);\n const senderPubKey = new Bytes32(txSender.PublicKey);\n\n if (logSettings) {\n console.log(\n \"Minting NFT through deterministic chain-generated id flow using these settings:\",\n JSON.stringify(cfg.toPrintable(), bigintReplacer, 2),\n );\n }\n\n const rom = PhantasmaNftRomBuilder.buildAndSerialize(\n cfg.nftRomSchema,\n cfg.nftMetadata\n );\n\n const feeOptions = new MintNftFeeOptions(\n cfg.gasFeeBase,\n cfg.gasFeeMultiplier,\n );\n\n const tx = MintPhantasmaNonFungibleTxHelper.buildTxAndSignHex(\n cfg.carbonTokenId,\n cfg.phantasmaSeriesId,\n txSender,\n senderPubKey,\n rom,\n new Uint8Array(),\n feeOptions,\n cfg.mintTokenMaxData,\n );\n\n if (dryRun) {\n console.log(`[dry-run] Prepared tx (not sent): ${tx}`);\n console.log(formatForLog(CarbonBlob.NewFromBytes(SignedTxMsg, hexToBytes(tx), 0)));\n return;\n }\n\n console.log(\"Broadcasting transaction...\");\n\n const rpc = new PhantasmaAPI(cfg.rpc, null, cfg.nexus);\n\n const txHash = requireRpcTxHash(\n await rpc.sendCarbonTransaction(tx),\n \"mint-nft transaction\",\n );\n console.log(\"txHash: \", txHash);\n\n const { success, result } = await waitForTx(rpc, txHash);\n\n if (success) {\n const mintResults = MintPhantasmaNonFungibleTxHelper.parseResult(result);\n if (mintResults.length === 0) {\n throw new Error(\"Deterministic mint result is empty\");\n }\n\n const carbonNftAddress = TokenHelper.getNftAddress(\n cfg.carbonTokenId,\n mintResults[0].carbonInstanceId,\n );\n const mintedPhantasmaNftIdHex = mintResults[0].phantasmaNftId.ToHex();\n const mintedPhantasmaNftId = bytes32HexToRpcDecimal(mintedPhantasmaNftIdHex);\n console.log(\n `Minted NFT with phantasma ID ${mintedPhantasmaNftId} (0x${mintedPhantasmaNftIdHex}) and carbon NFT address ${carbonNftAddress.ToHex()}`,\n );\n } else {\n console.log(\"Could not mint NFT\");\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-contract.d.ts","sourceRoot":"","sources":["../src/cli-contract.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli-contract.d.ts","sourceRoot":"","sources":["../src/cli-contract.ts"],"names":[],"mappings":"AAuMA,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAoLrE"}
|
package/dist/cli-contract.js
CHANGED
|
@@ -41,7 +41,7 @@ function parseOptionalInteger(value, flagName) {
|
|
|
41
41
|
return parsed;
|
|
42
42
|
}
|
|
43
43
|
async function handleContractCompile(argv) {
|
|
44
|
-
const compiler = await (0, compiler_1.resolveSupportedCompiler)(compiler_1.MIN_SUPPORTED_PHA_TOMB_VERSION);
|
|
44
|
+
const compiler = await (0, compiler_1.resolveSupportedCompiler)(compiler_1.MIN_SUPPORTED_PHA_TOMB_VERSION, process.env.PATH ?? "", argv.compiler ?? process.env.PHA_TOMB_PATH);
|
|
45
45
|
const sourcePath = node_path_1.default.resolve(argv.source);
|
|
46
46
|
const preferredContractName = argv.contractName?.trim() || node_path_1.default.basename(sourcePath, node_path_1.default.extname(sourcePath));
|
|
47
47
|
const outputDir = node_path_1.default.resolve(argv.out ?? node_path_1.default.join(process.cwd(), "dist", "contracts", preferredContractName));
|
|
@@ -112,10 +112,14 @@ async function handleContractBroadcast(operation, argv) {
|
|
|
112
112
|
proofOfWork: parseOptionalInteger(argv.pow, "--pow"),
|
|
113
113
|
payloadHex: argv.payloadHex,
|
|
114
114
|
dryRun: argv.dryRun,
|
|
115
|
+
attachSymbol: argv.symbol,
|
|
115
116
|
});
|
|
116
117
|
console.log("Transaction:");
|
|
117
118
|
console.log(` operation: ${result.prepared.operation}`);
|
|
118
119
|
console.log(` contract: ${result.prepared.contractName}`);
|
|
120
|
+
if (result.prepared.attachSymbol) {
|
|
121
|
+
console.log(` symbol: ${result.prepared.attachSymbol}`);
|
|
122
|
+
}
|
|
119
123
|
console.log(` from: ${result.prepared.fromAddress}`);
|
|
120
124
|
console.log(` script bytes: ${result.prepared.scriptBytes}`);
|
|
121
125
|
console.log(` abi bytes: ${result.prepared.abiBytes}`);
|
|
@@ -126,6 +130,9 @@ async function handleContractBroadcast(operation, argv) {
|
|
|
126
130
|
return;
|
|
127
131
|
}
|
|
128
132
|
console.log(` tx hash: ${result.txHash ?? ""}`);
|
|
133
|
+
if (result.broadcastError) {
|
|
134
|
+
throw new Error(result.broadcastError);
|
|
135
|
+
}
|
|
129
136
|
if (!result.success) {
|
|
130
137
|
throw new Error(`${operation} transaction failed${result.txHash ? ` (txHash: ${result.txHash})` : ""}`);
|
|
131
138
|
}
|
|
@@ -133,11 +140,15 @@ async function handleContractBroadcast(operation, argv) {
|
|
|
133
140
|
async function runContractCli(rawArgv) {
|
|
134
141
|
const parser = (0, yargs_1.default)(rawArgv)
|
|
135
142
|
.scriptName("pha-deploy contract")
|
|
136
|
-
.command("compile", "Compile a contract through
|
|
143
|
+
.command("compile", "Compile a contract through pha-tomb from PATH or an explicit override", (cmd) => cmd
|
|
137
144
|
.option("source", {
|
|
138
145
|
type: "string",
|
|
139
146
|
demandOption: true,
|
|
140
147
|
describe: "Path to the .tomb source file",
|
|
148
|
+
})
|
|
149
|
+
.option("compiler", {
|
|
150
|
+
type: "string",
|
|
151
|
+
describe: "Explicit pha-tomb executable path (overrides PHA_TOMB_PATH and PATH)",
|
|
141
152
|
})
|
|
142
153
|
.option("out", {
|
|
143
154
|
type: "string",
|
|
@@ -169,6 +180,7 @@ async function runContractCli(rawArgv) {
|
|
|
169
180
|
source: argv.source,
|
|
170
181
|
out: argv.out,
|
|
171
182
|
contractName: argv["contract-name"],
|
|
183
|
+
compiler: argv.compiler,
|
|
172
184
|
protocol: argv.protocol,
|
|
173
185
|
debug: argv.debug,
|
|
174
186
|
nativeCheck: argv.nativecheck,
|
|
@@ -238,6 +250,43 @@ async function runContractCli(rawArgv) {
|
|
|
238
250
|
payloadHex: argv["payload-hex"],
|
|
239
251
|
dryRun: argv["dry-run"],
|
|
240
252
|
});
|
|
253
|
+
})
|
|
254
|
+
.command("attach", "Attach a compiled contract bundle to an existing token symbol", (cmd) => cmd
|
|
255
|
+
.option("rpc", { type: "string", demandOption: true, describe: "RPC endpoint" })
|
|
256
|
+
.option("nexus", { type: "string", demandOption: true, describe: "Nexus name" })
|
|
257
|
+
.option("chain", { type: "string", default: "main", describe: "Target chain" })
|
|
258
|
+
.option("wif", { type: "string", demandOption: true, describe: "WIF used to sign the transaction" })
|
|
259
|
+
.option("symbol", {
|
|
260
|
+
type: "string",
|
|
261
|
+
describe: "Existing token symbol to attach to (defaults to the bundle contract name)",
|
|
262
|
+
})
|
|
263
|
+
.option("manifest", { type: "string", describe: "Path to manifest.json produced by contract compile" })
|
|
264
|
+
.option("contract-name", { type: "string", describe: "Contract name when using direct --script/--abi inputs" })
|
|
265
|
+
.option("script", { type: "string", describe: "Path to compiled .pvm file when not using --manifest" })
|
|
266
|
+
.option("abi", { type: "string", describe: "Path to compiled .abi file when not using --manifest" })
|
|
267
|
+
.option("debug", { type: "string", describe: "Optional path to .debug file when not using --manifest" })
|
|
268
|
+
.option("gas-price", { type: "number", describe: "Gas price passed to AllowGas" })
|
|
269
|
+
.option("gas-limit", { type: "number", describe: "Gas limit passed to AllowGas" })
|
|
270
|
+
.option("pow", { type: "number", describe: "Proof-of-work difficulty for the legacy VM transaction" })
|
|
271
|
+
.option("payload-hex", { type: "string", describe: "Optional transaction payload as raw hex" })
|
|
272
|
+
.option("dry-run", { type: "boolean", describe: "Build and sign the transaction without broadcasting" }), async (argv) => {
|
|
273
|
+
await handleContractBroadcast("attach", {
|
|
274
|
+
rpc: argv.rpc,
|
|
275
|
+
nexus: argv.nexus,
|
|
276
|
+
chain: argv.chain,
|
|
277
|
+
wif: argv.wif,
|
|
278
|
+
symbol: argv.symbol,
|
|
279
|
+
manifest: argv.manifest,
|
|
280
|
+
contractName: argv["contract-name"],
|
|
281
|
+
script: argv.script,
|
|
282
|
+
abi: argv.abi,
|
|
283
|
+
debug: argv.debug,
|
|
284
|
+
gasPrice: argv["gas-price"],
|
|
285
|
+
gasLimit: argv["gas-limit"],
|
|
286
|
+
pow: argv.pow,
|
|
287
|
+
payloadHex: argv["payload-hex"],
|
|
288
|
+
dryRun: argv["dry-run"],
|
|
289
|
+
});
|
|
241
290
|
})
|
|
242
291
|
.demandCommand(1)
|
|
243
292
|
.strict()
|