@alephium/web3 0.2.0-rc.10 → 0.2.0-rc.11
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/contracts/greeter_main.ral +1 -1
- package/dist/alephium-web3.min.js +1 -1
- package/dist/alephium-web3.min.js.map +1 -1
- package/dist/src/api/index.d.ts +1 -0
- package/dist/src/api/index.js +4 -0
- package/dist/src/api/types.d.ts +23 -0
- package/dist/src/api/types.js +240 -0
- package/dist/src/contract/contract.d.ts +15 -24
- package/dist/src/contract/contract.js +41 -231
- package/dist/src/contract/events.d.ts +4 -4
- package/dist/src/contract/ralph.d.ts +4 -4
- package/dist/src/signer/signer.d.ts +20 -10
- package/dist/src/signer/signer.js +38 -6
- package/dist/src/transaction/status.d.ts +2 -1
- package/package.json +1 -1
- package/src/api/index.ts +1 -0
- package/src/api/types.ts +233 -0
- package/src/contract/contract.ts +60 -236
- package/src/contract/events.ts +4 -4
- package/src/contract/ralph.ts +4 -4
- package/src/signer/signer.ts +67 -17
- package/src/transaction/status.ts +3 -1
- package/templates/base/package.json +1 -1
- package/templates/base/src/greeter.ts +4 -4
- package/templates/react/package.json +1 -1
|
@@ -43,11 +43,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.
|
|
46
|
+
exports.Script = exports.Contract = exports.Artifact = exports.Project = exports.DEFAULT_COMPILER_OPTIONS = exports.DEFAULT_NODE_COMPILER_OPTIONS = void 0;
|
|
47
47
|
const buffer_1 = require("buffer/");
|
|
48
48
|
const crypto_1 = require("crypto");
|
|
49
49
|
const fs_1 = __importDefault(require("fs"));
|
|
50
50
|
const fs_2 = require("fs");
|
|
51
|
+
const api_1 = require("../api");
|
|
51
52
|
const ralph = __importStar(require("./ralph"));
|
|
52
53
|
const utils_1 = require("../utils");
|
|
53
54
|
const global_1 = require("../global");
|
|
@@ -209,19 +210,17 @@ class Project {
|
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
212
|
}
|
|
212
|
-
static contract(
|
|
213
|
-
const
|
|
214
|
-
const contract = Project.currentProject.contracts.find((c) => c.sourceFile.contractPath === contractPath);
|
|
213
|
+
static contract(name) {
|
|
214
|
+
const contract = Project.currentProject.contracts.find((c) => c.artifact.name === name);
|
|
215
215
|
if (typeof contract === 'undefined') {
|
|
216
|
-
throw new Error(`Contract ${
|
|
216
|
+
throw new Error(`Contract "${name}" does not exist`);
|
|
217
217
|
}
|
|
218
218
|
return contract.artifact;
|
|
219
219
|
}
|
|
220
|
-
static script(
|
|
221
|
-
const
|
|
222
|
-
const script = Project.currentProject.scripts.find((c) => c.sourceFile.contractPath === contractPath);
|
|
220
|
+
static script(name) {
|
|
221
|
+
const script = Project.currentProject.scripts.find((c) => c.artifact.name === name);
|
|
223
222
|
if (typeof script === 'undefined') {
|
|
224
|
-
throw new Error(`Script ${
|
|
223
|
+
throw new Error(`Script "${name}" does not exist`);
|
|
225
224
|
}
|
|
226
225
|
return script.artifact;
|
|
227
226
|
}
|
|
@@ -368,7 +367,8 @@ Project.matchers = [
|
|
|
368
367
|
Project.scriptMatcher
|
|
369
368
|
];
|
|
370
369
|
class Artifact {
|
|
371
|
-
constructor(functions) {
|
|
370
|
+
constructor(name, functions) {
|
|
371
|
+
this.name = name;
|
|
372
372
|
this.functions = functions;
|
|
373
373
|
}
|
|
374
374
|
publicFunctions() {
|
|
@@ -383,8 +383,8 @@ class Artifact {
|
|
|
383
383
|
}
|
|
384
384
|
exports.Artifact = Artifact;
|
|
385
385
|
class Contract extends Artifact {
|
|
386
|
-
constructor(bytecode, codeHash, fieldsSig, eventsSig, functions) {
|
|
387
|
-
super(functions);
|
|
386
|
+
constructor(name, bytecode, codeHash, fieldsSig, eventsSig, functions) {
|
|
387
|
+
super(name, functions);
|
|
388
388
|
this.bytecode = bytecode;
|
|
389
389
|
this.codeHash = codeHash;
|
|
390
390
|
this.fieldsSig = fieldsSig;
|
|
@@ -392,18 +392,19 @@ class Contract extends Artifact {
|
|
|
392
392
|
}
|
|
393
393
|
// TODO: safely parse json
|
|
394
394
|
static fromJson(artifact) {
|
|
395
|
-
if (artifact.
|
|
395
|
+
if (artifact.name == null ||
|
|
396
|
+
artifact.bytecode == null ||
|
|
396
397
|
artifact.codeHash == null ||
|
|
397
398
|
artifact.fieldsSig == null ||
|
|
398
399
|
artifact.eventsSig == null ||
|
|
399
400
|
artifact.functions == null) {
|
|
400
401
|
throw Error('The artifact JSON for contract is incomplete');
|
|
401
402
|
}
|
|
402
|
-
const contract = new Contract(artifact.bytecode, artifact.codeHash, artifact.fieldsSig, artifact.eventsSig, artifact.functions);
|
|
403
|
+
const contract = new Contract(artifact.name, artifact.bytecode, artifact.codeHash, artifact.fieldsSig, artifact.eventsSig, artifact.functions);
|
|
403
404
|
return contract;
|
|
404
405
|
}
|
|
405
406
|
static fromCompileResult(result) {
|
|
406
|
-
return new Contract(result.bytecode, result.codeHash, result.fields, result.events, result.functions);
|
|
407
|
+
return new Contract(result.name, result.bytecode, result.codeHash, result.fields, result.events, result.functions);
|
|
407
408
|
}
|
|
408
409
|
// support both 'code.ral' and 'code.ral.json'
|
|
409
410
|
static async fromArtifactFile(path) {
|
|
@@ -419,6 +420,7 @@ class Contract extends Artifact {
|
|
|
419
420
|
}
|
|
420
421
|
toString() {
|
|
421
422
|
const object = {
|
|
423
|
+
name: this.name,
|
|
422
424
|
bytecode: this.bytecode,
|
|
423
425
|
codeHash: this.codeHash,
|
|
424
426
|
fieldsSig: this.fieldsSig,
|
|
@@ -543,7 +545,7 @@ class Contract extends Artifact {
|
|
|
543
545
|
return {
|
|
544
546
|
address: result.address,
|
|
545
547
|
contractId: (0, utils_1.binToHex)((0, utils_1.contractIdFromAddress)(result.address)),
|
|
546
|
-
returns: fromApiArray(result.returns, this.functions[`${methodIndex}`].returnTypes),
|
|
548
|
+
returns: (0, api_1.fromApiArray)(result.returns, this.functions[`${methodIndex}`].returnTypes),
|
|
547
549
|
gasUsed: result.gasUsed,
|
|
548
550
|
contracts: await Promise.all(result.contracts.map((contract) => this.fromApiContractState(contract))),
|
|
549
551
|
txOutputs: result.txOutputs.map(fromApiOutput),
|
|
@@ -566,7 +568,7 @@ class Contract extends Artifact {
|
|
|
566
568
|
bytecode: bytecode,
|
|
567
569
|
initialAttoAlphAmount: extractOptionalNumber256(params.initialAttoAlphAmount),
|
|
568
570
|
issueTokenAmount: extractOptionalNumber256(params.issueTokenAmount),
|
|
569
|
-
initialTokenAmounts: params.initialTokenAmounts
|
|
571
|
+
initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
|
|
570
572
|
gasAmount: params.gasAmount,
|
|
571
573
|
gasPrice: extractOptionalNumber256(params.gasPrice)
|
|
572
574
|
};
|
|
@@ -596,20 +598,23 @@ Contract.ContractDestroyedEvent = {
|
|
|
596
598
|
fieldTypes: ['Address']
|
|
597
599
|
};
|
|
598
600
|
class Script extends Artifact {
|
|
599
|
-
constructor(bytecodeTemplate, fieldsSig, functions) {
|
|
600
|
-
super(functions);
|
|
601
|
+
constructor(name, bytecodeTemplate, fieldsSig, functions) {
|
|
602
|
+
super(name, functions);
|
|
601
603
|
this.bytecodeTemplate = bytecodeTemplate;
|
|
602
604
|
this.fieldsSig = fieldsSig;
|
|
603
605
|
}
|
|
604
606
|
static fromCompileResult(result) {
|
|
605
|
-
return new Script(result.bytecodeTemplate, result.fields, result.functions);
|
|
607
|
+
return new Script(result.name, result.bytecodeTemplate, result.fields, result.functions);
|
|
606
608
|
}
|
|
607
609
|
// TODO: safely parse json
|
|
608
610
|
static fromJson(artifact) {
|
|
609
|
-
if (artifact.
|
|
611
|
+
if (artifact.name == null ||
|
|
612
|
+
artifact.bytecodeTemplate == null ||
|
|
613
|
+
artifact.fieldsSig == null ||
|
|
614
|
+
artifact.functions == null) {
|
|
610
615
|
throw Error('The artifact JSON for script is incomplete');
|
|
611
616
|
}
|
|
612
|
-
return new Script(artifact.bytecodeTemplate, artifact.fieldsSig, artifact.functions);
|
|
617
|
+
return new Script(artifact.name, artifact.bytecodeTemplate, artifact.fieldsSig, artifact.functions);
|
|
613
618
|
}
|
|
614
619
|
static async fromArtifactFile(path) {
|
|
615
620
|
const content = await fs_2.promises.readFile(path);
|
|
@@ -618,6 +623,7 @@ class Script extends Artifact {
|
|
|
618
623
|
}
|
|
619
624
|
toString() {
|
|
620
625
|
const object = {
|
|
626
|
+
name: this.name,
|
|
621
627
|
bytecodeTemplate: this.bytecodeTemplate,
|
|
622
628
|
fieldsSig: this.fieldsSig,
|
|
623
629
|
functions: this.functions
|
|
@@ -629,7 +635,7 @@ class Script extends Artifact {
|
|
|
629
635
|
signerAddress: params.signerAddress,
|
|
630
636
|
bytecode: this.buildByteCodeToDeploy(params.initialFields ? params.initialFields : {}),
|
|
631
637
|
attoAlphAmount: extractOptionalNumber256(params.attoAlphAmount),
|
|
632
|
-
tokens:
|
|
638
|
+
tokens: (0, api_1.toApiTokens)(params.tokens),
|
|
633
639
|
gasAmount: params.gasAmount,
|
|
634
640
|
gasPrice: extractOptionalNumber256(params.gasPrice)
|
|
635
641
|
};
|
|
@@ -647,221 +653,25 @@ class Script extends Artifact {
|
|
|
647
653
|
}
|
|
648
654
|
}
|
|
649
655
|
exports.Script = Script;
|
|
650
|
-
function extractBoolean(v) {
|
|
651
|
-
if (typeof v === 'boolean') {
|
|
652
|
-
return v;
|
|
653
|
-
}
|
|
654
|
-
else {
|
|
655
|
-
throw new Error(`Invalid boolean value: ${v}`);
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
// TODO: check integer bounds
|
|
659
|
-
function extractNumber256(v) {
|
|
660
|
-
if ((typeof v === 'number' && Number.isInteger(v)) || typeof v === 'bigint') {
|
|
661
|
-
return v.toString();
|
|
662
|
-
}
|
|
663
|
-
else if (typeof v === 'string') {
|
|
664
|
-
return v;
|
|
665
|
-
}
|
|
666
|
-
else {
|
|
667
|
-
throw new Error(`Invalid 256 bit number: ${v}`);
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
656
|
function extractOptionalNumber256(v) {
|
|
671
|
-
return typeof v !== 'undefined' ?
|
|
672
|
-
}
|
|
673
|
-
// TODO: check hex string
|
|
674
|
-
function extractByteVec(v) {
|
|
675
|
-
if (typeof v === 'string') {
|
|
676
|
-
// try to convert from address to contract id
|
|
677
|
-
try {
|
|
678
|
-
const address = utils_1.bs58.decode(v);
|
|
679
|
-
if (address.length == 33 && address[0] == 3) {
|
|
680
|
-
return buffer_1.Buffer.from(address.slice(1)).toString('hex');
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
catch (_) {
|
|
684
|
-
return v;
|
|
685
|
-
}
|
|
686
|
-
return v;
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
throw new Error(`Invalid string: ${v}`);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
function extractBs58(v) {
|
|
693
|
-
if (typeof v === 'string') {
|
|
694
|
-
try {
|
|
695
|
-
utils_1.bs58.decode(v);
|
|
696
|
-
return v;
|
|
697
|
-
}
|
|
698
|
-
catch (error) {
|
|
699
|
-
throw new Error(`Invalid base58 string: ${v}`);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
else {
|
|
703
|
-
throw new Error(`Invalid string: ${v}`);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
function decodeNumber256(n) {
|
|
707
|
-
if (Number.isSafeInteger(Number.parseInt(n))) {
|
|
708
|
-
return Number(n);
|
|
709
|
-
}
|
|
710
|
-
else {
|
|
711
|
-
return BigInt(n);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
function extractArray(tpe, v) {
|
|
715
|
-
if (!Array.isArray(v)) {
|
|
716
|
-
throw new Error(`Expected array, got ${v}`);
|
|
717
|
-
}
|
|
718
|
-
const semiColonIndex = tpe.lastIndexOf(';');
|
|
719
|
-
if (semiColonIndex == -1) {
|
|
720
|
-
throw new Error(`Invalid Val type: ${tpe}`);
|
|
721
|
-
}
|
|
722
|
-
const subType = tpe.slice(1, semiColonIndex);
|
|
723
|
-
const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
|
|
724
|
-
if (v.length != dim) {
|
|
725
|
-
throw new Error(`Invalid val dimension: ${v}`);
|
|
726
|
-
}
|
|
727
|
-
else {
|
|
728
|
-
return { value: v.map((v) => toApiVal(v, subType)), type: 'Array' };
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
exports.extractArray = extractArray;
|
|
732
|
-
function toApiVal(v, tpe) {
|
|
733
|
-
if (tpe === 'Bool') {
|
|
734
|
-
return { value: extractBoolean(v), type: tpe };
|
|
735
|
-
}
|
|
736
|
-
else if (tpe === 'U256' || tpe === 'I256') {
|
|
737
|
-
return { value: extractNumber256(v), type: tpe };
|
|
738
|
-
}
|
|
739
|
-
else if (tpe === 'ByteVec') {
|
|
740
|
-
return { value: extractByteVec(v), type: tpe };
|
|
741
|
-
}
|
|
742
|
-
else if (tpe === 'Address') {
|
|
743
|
-
return { value: extractBs58(v), type: tpe };
|
|
744
|
-
}
|
|
745
|
-
else {
|
|
746
|
-
return extractArray(tpe, v);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
exports.toApiVal = toApiVal;
|
|
750
|
-
function decodeArrayType(tpe) {
|
|
751
|
-
const semiColonIndex = tpe.lastIndexOf(';');
|
|
752
|
-
if (semiColonIndex === -1) {
|
|
753
|
-
throw new Error(`Invalid Val type: ${tpe}`);
|
|
754
|
-
}
|
|
755
|
-
const subType = tpe.slice(1, semiColonIndex);
|
|
756
|
-
const dim = parseInt(tpe.slice(semiColonIndex + 1, -1));
|
|
757
|
-
if (subType[0] == '[') {
|
|
758
|
-
const [baseType, subDim] = decodeArrayType(subType);
|
|
759
|
-
return [baseType, (subDim.unshift(dim), subDim)];
|
|
760
|
-
}
|
|
761
|
-
else {
|
|
762
|
-
return [subType, [dim]];
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
function foldVals(vals, dims) {
|
|
766
|
-
if (dims.length == 1) {
|
|
767
|
-
return vals;
|
|
768
|
-
}
|
|
769
|
-
else {
|
|
770
|
-
const result = [];
|
|
771
|
-
const chunkSize = vals.length / dims[0];
|
|
772
|
-
const chunkDims = dims.slice(1);
|
|
773
|
-
for (let i = 0; i < vals.length; i += chunkSize) {
|
|
774
|
-
const chunk = vals.slice(i, i + chunkSize);
|
|
775
|
-
result.push(foldVals(chunk, chunkDims));
|
|
776
|
-
}
|
|
777
|
-
return result;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
function _fromApiVal(vals, valIndex, tpe) {
|
|
781
|
-
if (vals.length === 0) {
|
|
782
|
-
throw new Error('Not enough Vals');
|
|
783
|
-
}
|
|
784
|
-
const firstVal = vals[`${valIndex}`];
|
|
785
|
-
if (tpe === 'Bool' && firstVal.type === tpe) {
|
|
786
|
-
return [firstVal.value, valIndex + 1];
|
|
787
|
-
}
|
|
788
|
-
else if ((tpe === 'U256' || tpe === 'I256') && firstVal.type === tpe) {
|
|
789
|
-
return [decodeNumber256(firstVal.value), valIndex + 1];
|
|
790
|
-
}
|
|
791
|
-
else if ((tpe === 'ByteVec' || tpe === 'Address') && firstVal.type === tpe) {
|
|
792
|
-
return [firstVal.value, valIndex + 1];
|
|
793
|
-
}
|
|
794
|
-
else {
|
|
795
|
-
const [baseType, dims] = decodeArrayType(tpe);
|
|
796
|
-
const arraySize = dims.reduce((a, b) => a * b);
|
|
797
|
-
const nextIndex = valIndex + arraySize;
|
|
798
|
-
const valsToUse = vals.slice(valIndex, nextIndex);
|
|
799
|
-
if (valsToUse.length == arraySize && valsToUse.every((val) => val.type === baseType)) {
|
|
800
|
-
const localVals = valsToUse.map((val) => fromApiVal(val, baseType));
|
|
801
|
-
return [foldVals(localVals, dims), nextIndex];
|
|
802
|
-
}
|
|
803
|
-
else {
|
|
804
|
-
throw new Error(`Invalid array Val type: ${valsToUse}, ${tpe}`);
|
|
805
|
-
}
|
|
806
|
-
}
|
|
657
|
+
return typeof v !== 'undefined' ? (0, api_1.toApiNumber256)(v) : undefined;
|
|
807
658
|
}
|
|
808
659
|
function fromApiFields(vals, fieldsSig) {
|
|
809
|
-
return fromApiVals(vals, fieldsSig.names, fieldsSig.types);
|
|
660
|
+
return (0, api_1.fromApiVals)(vals, fieldsSig.names, fieldsSig.types);
|
|
810
661
|
}
|
|
811
662
|
function fromApiEventFields(vals, eventSig) {
|
|
812
|
-
return fromApiVals(vals, eventSig.fieldNames, eventSig.fieldTypes);
|
|
813
|
-
}
|
|
814
|
-
function fromApiVals(vals, names, types) {
|
|
815
|
-
let valIndex = 0;
|
|
816
|
-
const result = {};
|
|
817
|
-
types.forEach((currentType, index) => {
|
|
818
|
-
const currentName = names[`${index}`];
|
|
819
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
|
|
820
|
-
valIndex = nextIndex;
|
|
821
|
-
result[`${currentName}`] = val;
|
|
822
|
-
});
|
|
823
|
-
return result;
|
|
824
|
-
}
|
|
825
|
-
function fromApiArray(vals, types) {
|
|
826
|
-
let valIndex = 0;
|
|
827
|
-
const result = [];
|
|
828
|
-
for (const currentType of types) {
|
|
829
|
-
const [val, nextIndex] = _fromApiVal(vals, valIndex, currentType);
|
|
830
|
-
result.push(val);
|
|
831
|
-
valIndex = nextIndex;
|
|
832
|
-
}
|
|
833
|
-
return result;
|
|
834
|
-
}
|
|
835
|
-
function fromApiVal(v, tpe) {
|
|
836
|
-
if (v.type === 'Bool' && v.type === tpe) {
|
|
837
|
-
return v.value;
|
|
838
|
-
}
|
|
839
|
-
else if ((v.type === 'U256' || v.type === 'I256') && v.type === tpe) {
|
|
840
|
-
return decodeNumber256(v.value);
|
|
841
|
-
}
|
|
842
|
-
else if ((v.type === 'ByteVec' || v.type === 'Address') && v.type === tpe) {
|
|
843
|
-
return v.value;
|
|
844
|
-
}
|
|
845
|
-
else {
|
|
846
|
-
throw new Error(`Invalid node.Val type: ${v}`);
|
|
847
|
-
}
|
|
848
|
-
}
|
|
849
|
-
function toApiToken(token) {
|
|
850
|
-
return { id: token.id, amount: extractNumber256(token.amount) };
|
|
851
|
-
}
|
|
852
|
-
function fromApiToken(token) {
|
|
853
|
-
return { id: token.id, amount: decodeNumber256(token.amount) };
|
|
663
|
+
return (0, api_1.fromApiVals)(vals, eventSig.fieldNames, eventSig.fieldTypes);
|
|
854
664
|
}
|
|
855
665
|
function toApiAsset(asset) {
|
|
856
666
|
return {
|
|
857
|
-
attoAlphAmount:
|
|
858
|
-
tokens: typeof asset.tokens !== 'undefined' ? asset.tokens.map(toApiToken) : []
|
|
667
|
+
attoAlphAmount: (0, api_1.toApiNumber256)(asset.alphAmount),
|
|
668
|
+
tokens: typeof asset.tokens !== 'undefined' ? asset.tokens.map(api_1.toApiToken) : []
|
|
859
669
|
};
|
|
860
670
|
}
|
|
861
671
|
function fromApiAsset(asset) {
|
|
862
672
|
return {
|
|
863
|
-
alphAmount:
|
|
864
|
-
tokens:
|
|
673
|
+
alphAmount: (0, api_1.fromApiNumber256)(asset.attoAlphAmount),
|
|
674
|
+
tokens: (0, api_1.fromApiTokens)(asset.tokens)
|
|
865
675
|
};
|
|
866
676
|
}
|
|
867
677
|
function getVal(vals, name) {
|
|
@@ -892,7 +702,7 @@ function toApiVals(fields, names, types) {
|
|
|
892
702
|
return names.map((name, index) => {
|
|
893
703
|
const val = getVal(fields, name);
|
|
894
704
|
const tpe = types[`${index}`];
|
|
895
|
-
return toApiVal(val, tpe);
|
|
705
|
+
return (0, api_1.toApiVal)(val, tpe);
|
|
896
706
|
});
|
|
897
707
|
}
|
|
898
708
|
function toApiInputAsset(inputAsset) {
|
|
@@ -907,8 +717,8 @@ function fromApiOutput(output) {
|
|
|
907
717
|
return {
|
|
908
718
|
type: 'AssetOutput',
|
|
909
719
|
address: asset.address,
|
|
910
|
-
alphAmount:
|
|
911
|
-
tokens: asset.tokens
|
|
720
|
+
alphAmount: (0, api_1.fromApiNumber256)(asset.attoAlphAmount),
|
|
721
|
+
tokens: (0, api_1.fromApiTokens)(asset.tokens),
|
|
912
722
|
lockTime: asset.lockTime,
|
|
913
723
|
message: asset.message
|
|
914
724
|
};
|
|
@@ -918,8 +728,8 @@ function fromApiOutput(output) {
|
|
|
918
728
|
return {
|
|
919
729
|
type: 'ContractOutput',
|
|
920
730
|
address: asset.address,
|
|
921
|
-
alphAmount:
|
|
922
|
-
tokens: asset.tokens
|
|
731
|
+
alphAmount: (0, api_1.fromApiNumber256)(asset.attoAlphAmount),
|
|
732
|
+
tokens: (0, api_1.fromApiTokens)(asset.tokens)
|
|
923
733
|
};
|
|
924
734
|
}
|
|
925
735
|
else {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { node } from '../api';
|
|
2
2
|
import { Subscription, SubscribeOptions } from '../utils';
|
|
3
|
-
export declare class EventSubscription extends Subscription<ContractEvent> {
|
|
3
|
+
export declare class EventSubscription extends Subscription<node.ContractEvent> {
|
|
4
4
|
readonly contractAddress: string;
|
|
5
5
|
private fromCount;
|
|
6
|
-
constructor(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number);
|
|
6
|
+
constructor(options: SubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number);
|
|
7
7
|
startPolling(): void;
|
|
8
8
|
currentEventCount(): number;
|
|
9
9
|
polling(): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
export declare function subscribeToEvents(options: SubscribeOptions<ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
|
|
11
|
+
export declare function subscribeToEvents(options: SubscribeOptions<node.ContractEvent>, contractAddress: string, fromCount?: number): EventSubscription;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Fields,
|
|
1
|
+
import { Val } from '../api';
|
|
2
|
+
import { Fields, FieldsSig } from './contract';
|
|
3
3
|
export declare function encodeBool(bool: boolean): Uint8Array;
|
|
4
4
|
export declare function encodeI256(i256: bigint): Uint8Array;
|
|
5
5
|
export declare function encodeU256(u256: bigint): Uint8Array;
|
|
@@ -7,6 +7,6 @@ export declare function encodeByteVec(bytes: string): Uint8Array;
|
|
|
7
7
|
export declare function encodeAddress(address: string): Uint8Array;
|
|
8
8
|
export declare function encodeScriptFieldAsString(tpe: string, value: Val): string;
|
|
9
9
|
export declare function encodeScriptField(tpe: string, value: Val): Uint8Array;
|
|
10
|
-
export declare function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fieldsSig:
|
|
11
|
-
export declare function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig:
|
|
10
|
+
export declare function buildScriptByteCode(bytecodeTemplate: string, fields: Fields, fieldsSig: FieldsSig): string;
|
|
11
|
+
export declare function buildContractByteCode(bytecode: string, fields: Fields, fieldsSig: FieldsSig): string;
|
|
12
12
|
export declare function encodeContractField(tpe: string, value: Val): Uint8Array[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { NodeProvider } from '../api';
|
|
1
|
+
import { NodeProvider, Number256, Token } from '../api';
|
|
2
2
|
import { node } from '../api';
|
|
3
|
-
|
|
3
|
+
export declare type OutputRef = node.OutputRef;
|
|
4
4
|
export interface SignResult {
|
|
5
5
|
fromGroup: number;
|
|
6
6
|
toGroup: number;
|
|
@@ -23,10 +23,10 @@ export declare type GetAccountsParams = undefined;
|
|
|
23
23
|
export declare type GetAccountsResult = Account[];
|
|
24
24
|
export interface SignTransferTxParams {
|
|
25
25
|
signerAddress: string;
|
|
26
|
-
destinations:
|
|
27
|
-
utxos?:
|
|
26
|
+
destinations: Destination[];
|
|
27
|
+
utxos?: OutputRef[];
|
|
28
28
|
gasAmount?: number;
|
|
29
|
-
gasPrice?:
|
|
29
|
+
gasPrice?: Number256;
|
|
30
30
|
submitTx?: boolean;
|
|
31
31
|
}
|
|
32
32
|
export interface SignTransferTxResult {
|
|
@@ -39,11 +39,11 @@ export interface SignTransferTxResult {
|
|
|
39
39
|
export interface SignDeployContractTxParams {
|
|
40
40
|
signerAddress: string;
|
|
41
41
|
bytecode: string;
|
|
42
|
-
initialAttoAlphAmount?:
|
|
42
|
+
initialAttoAlphAmount?: Number256;
|
|
43
43
|
initialTokenAmounts?: Token[];
|
|
44
|
-
issueTokenAmount?:
|
|
44
|
+
issueTokenAmount?: Number256;
|
|
45
45
|
gasAmount?: number;
|
|
46
|
-
gasPrice?:
|
|
46
|
+
gasPrice?: Number256;
|
|
47
47
|
submitTx?: boolean;
|
|
48
48
|
}
|
|
49
49
|
export interface SignDeployContractTxResult {
|
|
@@ -59,7 +59,7 @@ export interface SignExecuteScriptTxParams {
|
|
|
59
59
|
signerAddress: string;
|
|
60
60
|
bytecode: string;
|
|
61
61
|
attoAlphAmount?: string;
|
|
62
|
-
tokens?:
|
|
62
|
+
tokens?: Token[];
|
|
63
63
|
gasAmount?: number;
|
|
64
64
|
gasPrice?: string;
|
|
65
65
|
submitTx?: boolean;
|
|
@@ -113,7 +113,7 @@ export declare abstract class SignerWithNodeProvider implements SignerProvider {
|
|
|
113
113
|
getAccount(signerAddress: string): Promise<Account>;
|
|
114
114
|
constructor(alwaysSubmitTx: boolean);
|
|
115
115
|
private defaultSignerAddress;
|
|
116
|
-
submitTransaction(unsignedTx: string,
|
|
116
|
+
submitTransaction(unsignedTx: string, signerAddress?: string): Promise<SubmissionResult>;
|
|
117
117
|
private shouldSubmitTx;
|
|
118
118
|
private usePublicKey;
|
|
119
119
|
signTransferTx(params: SignTransferTxParams): Promise<SignTransferTxResult>;
|
|
@@ -141,3 +141,13 @@ export interface SubmissionResult {
|
|
|
141
141
|
}
|
|
142
142
|
export declare function verifyHexString(hexString: string, publicKey: string, signature: string): boolean;
|
|
143
143
|
export declare function verifySignedMessage(message: string, publicKey: string, signature: string): boolean;
|
|
144
|
+
export interface Destination {
|
|
145
|
+
address: string;
|
|
146
|
+
attoAlphAmount: Number256;
|
|
147
|
+
tokens?: Token[];
|
|
148
|
+
lockTime?: number;
|
|
149
|
+
message?: string;
|
|
150
|
+
}
|
|
151
|
+
export declare function toApiDestination(data: Destination): node.Destination;
|
|
152
|
+
export declare function toApiDestinations(data: Destination[]): node.Destination[];
|
|
153
|
+
export declare function fromApiDestination(data: node.Destination): Destination;
|
|
@@ -43,8 +43,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
43
43
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
44
|
};
|
|
45
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
exports.verifySignedMessage = exports.verifyHexString = exports.SignerWithNodeProvider = void 0;
|
|
46
|
+
exports.fromApiDestination = exports.toApiDestinations = exports.toApiDestination = exports.verifySignedMessage = exports.verifyHexString = exports.SignerWithNodeProvider = void 0;
|
|
47
47
|
const elliptic_1 = require("elliptic");
|
|
48
|
+
const api_1 = require("../api");
|
|
48
49
|
const utils = __importStar(require("../utils"));
|
|
49
50
|
const utils_1 = require("../utils");
|
|
50
51
|
const blakejs_1 = __importDefault(require("blakejs"));
|
|
@@ -80,9 +81,11 @@ class SignerWithNodeProvider {
|
|
|
80
81
|
async defaultSignerAddress() {
|
|
81
82
|
return (await this.getAccounts())[0].address;
|
|
82
83
|
}
|
|
83
|
-
async submitTransaction(unsignedTx,
|
|
84
|
+
async submitTransaction(unsignedTx, signerAddress) {
|
|
85
|
+
const decoded = await this.provider.transactions.postTransactionsDecodeUnsignedTx({ unsignedTx: unsignedTx });
|
|
86
|
+
const txId = decoded.unsignedTx.txId;
|
|
84
87
|
const address = typeof signerAddress !== 'undefined' ? signerAddress : await this.defaultSignerAddress();
|
|
85
|
-
const signature = await this.signRaw(address,
|
|
88
|
+
const signature = await this.signRaw(address, txId);
|
|
86
89
|
const params = { unsignedTx: unsignedTx, signature: signature };
|
|
87
90
|
return this.provider.transactions.postTransactionsSubmit(params);
|
|
88
91
|
}
|
|
@@ -105,7 +108,12 @@ class SignerWithNodeProvider {
|
|
|
105
108
|
return this.handleSign({ signerAddress: params.signerAddress, ...response }, this.shouldSubmitTx(params));
|
|
106
109
|
}
|
|
107
110
|
async buildTransferTx(params) {
|
|
108
|
-
|
|
111
|
+
const data = {
|
|
112
|
+
...(await this.usePublicKey(params)),
|
|
113
|
+
destinations: toApiDestinations(params.destinations),
|
|
114
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
115
|
+
};
|
|
116
|
+
return this.provider.transactions.postTransactionsBuild(data);
|
|
109
117
|
}
|
|
110
118
|
async signDeployContractTx(params) {
|
|
111
119
|
const response = await this.buildContractCreationTx(params);
|
|
@@ -114,14 +122,25 @@ class SignerWithNodeProvider {
|
|
|
114
122
|
return { ...result, contractId: contractId, contractAddress: response.contractAddress };
|
|
115
123
|
}
|
|
116
124
|
async buildContractCreationTx(params) {
|
|
117
|
-
|
|
125
|
+
const data = {
|
|
126
|
+
...(await this.usePublicKey(params)),
|
|
127
|
+
initialAttoAlphAmount: (0, api_1.toApiNumber256Optional)(params.initialAttoAlphAmount),
|
|
128
|
+
initialTokenAmounts: (0, api_1.toApiTokens)(params.initialTokenAmounts),
|
|
129
|
+
issueTokenAmount: (0, api_1.toApiNumber256Optional)(params.issueTokenAmount),
|
|
130
|
+
gasPrice: (0, api_1.toApiNumber256Optional)(params.gasPrice)
|
|
131
|
+
};
|
|
132
|
+
return this.provider.contracts.postContractsUnsignedTxDeployContract(data);
|
|
118
133
|
}
|
|
119
134
|
async signExecuteScriptTx(params) {
|
|
120
135
|
const response = await this.buildScriptTx(params);
|
|
121
136
|
return this.handleSign({ signerAddress: params.signerAddress, ...response }, this.shouldSubmitTx(params));
|
|
122
137
|
}
|
|
123
138
|
async buildScriptTx(params) {
|
|
124
|
-
|
|
139
|
+
const data = {
|
|
140
|
+
...(await this.usePublicKey(params)),
|
|
141
|
+
tokens: (0, api_1.toApiTokens)(params.tokens)
|
|
142
|
+
};
|
|
143
|
+
return this.provider.contracts.postContractsUnsignedTxExecuteScript(data);
|
|
125
144
|
}
|
|
126
145
|
// in general, wallet should show the decoded information to user for confirmation
|
|
127
146
|
// please overwrite this function for real wallet
|
|
@@ -187,3 +206,16 @@ function verifySignedMessage(message, publicKey, signature) {
|
|
|
187
206
|
return verifyHexString(utils.binToHex(messageHash), publicKey, signature);
|
|
188
207
|
}
|
|
189
208
|
exports.verifySignedMessage = verifySignedMessage;
|
|
209
|
+
utils_1.assertType;
|
|
210
|
+
function toApiDestination(data) {
|
|
211
|
+
return { ...data, attoAlphAmount: (0, api_1.toApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.toApiTokens)(data.tokens) };
|
|
212
|
+
}
|
|
213
|
+
exports.toApiDestination = toApiDestination;
|
|
214
|
+
function toApiDestinations(data) {
|
|
215
|
+
return data.map(toApiDestination);
|
|
216
|
+
}
|
|
217
|
+
exports.toApiDestinations = toApiDestinations;
|
|
218
|
+
function fromApiDestination(data) {
|
|
219
|
+
return { ...data, attoAlphAmount: (0, api_1.fromApiNumber256)(data.attoAlphAmount), tokens: (0, api_1.fromApiTokens)(data.tokens) };
|
|
220
|
+
}
|
|
221
|
+
exports.fromApiDestination = fromApiDestination;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { node } from '../api';
|
|
2
2
|
import { Subscription, SubscribeOptions } from '../utils';
|
|
3
|
+
export declare type TxStatus = node.TxStatus;
|
|
3
4
|
export declare class TxStatusSubscription extends Subscription<TxStatus> {
|
|
4
5
|
readonly txId: string;
|
|
5
6
|
readonly fromGroup?: number;
|
package/package.json
CHANGED
package/src/api/index.ts
CHANGED