scryptlib
Advanced tools
Comparing version 0.2.23-beta1 to 0.2.23
# CHANGELOG | ||
## 0.2.23 | ||
* add struct support | ||
* add static getAsmvars fn | ||
* change rename to renameSync | ||
* return error position with start/end in SemanticError | ||
## 0.2.22 | ||
@@ -5,0 +12,0 @@ |
import { AbstractContract, TxContext, VerifyResult, AsmVarValues } from './contract'; | ||
import { SingletonParamType, SupportedParamType, Struct } from './scryptTypes'; | ||
import { SingletonParamType, SupportedParamType } from './scryptTypes'; | ||
import { ABIEntity, StructEntity } from './compilerWrapper'; | ||
@@ -36,4 +36,3 @@ export interface Script { | ||
encodeParamArray(args: SingletonParamType[], arrayTypeName: string): string; | ||
encodeParamStruct(arg: Struct, structTypeName: string): string; | ||
encodeParam(arg: SupportedParamType, scryptTypeName: string): string; | ||
} |
@@ -163,11 +163,2 @@ "use strict"; | ||
} | ||
encodeParamStruct(arg, structTypeName) { | ||
const s = utils_1.findStructByType(structTypeName, this.structs); | ||
if (s) { | ||
return s.params.map(e => this.encodeParam(arg.value[e.name], e.type)).join(' '); | ||
} | ||
else { | ||
throw new Error(`struct ${structTypeName} does not exist`); | ||
} | ||
} | ||
encodeParam(arg, scryptTypeName) { | ||
@@ -174,0 +165,0 @@ if (Array.isArray(arg)) { |
@@ -110,2 +110,4 @@ import { StructEntity } from "./compilerWrapper"; | ||
memberByIndex(index: number): string; | ||
getMemberType(key: string): string; | ||
getMembers(): string[]; | ||
toLiteral(): string; | ||
@@ -112,0 +114,0 @@ static isStruct(arg: SupportedParamType): boolean; |
@@ -306,2 +306,24 @@ "use strict"; | ||
} | ||
getMemberType(key) { | ||
const v = this.value; | ||
if (v[key] instanceof ScryptType) { | ||
return v[key].type; | ||
} | ||
else if (typeof v[key] === "boolean") { | ||
return new Bool(v[key]).type; | ||
} | ||
else if (typeof v[key] === "number") { | ||
return new Int(v[key]).type; | ||
} | ||
else if (typeof v[key] === "bigint") { | ||
return new Int(v[key]).type; | ||
} | ||
else { | ||
return typeof v[key]; | ||
} | ||
} | ||
getMembers() { | ||
const v = this.value; | ||
return Object.keys(v); | ||
} | ||
toLiteral() { | ||
@@ -308,0 +330,0 @@ const v = this.value; |
@@ -384,17 +384,19 @@ "use strict"; | ||
function checkStruct(s, arg) { | ||
const members = s.params.map(p => p.name); | ||
const props = []; | ||
for (const p in arg.value) { | ||
if (!members.includes(p)) { | ||
throw new Error(`${p} is not a member of struct ${s.name}`); | ||
s.params.forEach(p => { | ||
const type = arg.getMemberType(p.name); | ||
if (type === 'undefined') { | ||
throw new Error(`argument of type struct ${s.name} missing member ${p.name}`); | ||
} | ||
props.push(p); | ||
} | ||
members.forEach(key => { | ||
if (!props.includes(key)) { | ||
throw new Error(`argument of type struct ${s.name} missing member ${key}`); | ||
else if (type != p.type) { | ||
throw new Error(`wrong argument type, expected ${p.type} but got ${type}`); | ||
} | ||
}); | ||
const members = s.params.map(p => p.name); | ||
arg.getMembers().forEach(key => { | ||
if (!members.includes(key)) { | ||
throw new Error(`${key} is not a member of struct ${s.name}`); | ||
} | ||
}); | ||
} | ||
exports.checkStruct = checkStruct; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "scryptlib", | ||
"version": "0.2.23-beta1", | ||
"version": "0.2.23", | ||
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.", | ||
@@ -5,0 +5,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
93150
2052