scryptlib
Advanced tools
Comparing version 0.1.8 to 0.1.9
# CHANGELOG | ||
## 0.1.9 | ||
* support ASM variable instantiation | ||
## 0.1.8 | ||
@@ -4,0 +8,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { AbstractContract, TxContext, VerifyResult } from './contract'; | ||
import { AbstractContract, TxContext, VerifyResult, AsmVarValues } from './contract'; | ||
import { ScryptType } from './scryptTypes'; | ||
@@ -25,4 +25,7 @@ export declare enum ABIEntityType { | ||
readonly contract: AbstractContract; | ||
readonly lockingScript?: Script; | ||
readonly unlockingScript?: Script; | ||
private _unlockingScriptAsm?; | ||
private _lockingScriptAsm?; | ||
get unlockingScript(): Script | undefined; | ||
get lockingScript(): Script | undefined; | ||
init(asmVarValues: AsmVarValues): void; | ||
constructor(methodName: string, params: SupportedParamType[], binding: { | ||
@@ -29,0 +32,0 @@ contract: AbstractContract; |
@@ -21,8 +21,21 @@ "use strict"; | ||
if (binding.lockingScriptASM) { | ||
this.lockingScript = utils_1.bsv.Script.fromASM(binding.lockingScriptASM); | ||
this._lockingScriptAsm = binding.lockingScriptASM; | ||
} | ||
if (binding.unlockingScriptASM) { | ||
this.unlockingScript = utils_1.bsv.Script.fromASM(binding.unlockingScriptASM); | ||
this._unlockingScriptAsm = binding.unlockingScriptASM; | ||
} | ||
} | ||
get unlockingScript() { | ||
return this._unlockingScriptAsm === undefined ? undefined : utils_1.bsv.Script.fromASM(this._unlockingScriptAsm); | ||
} | ||
get lockingScript() { | ||
return this._lockingScriptAsm === undefined ? undefined : utils_1.bsv.Script.fromASM(this._lockingScriptAsm); | ||
} | ||
init(asmVarValues) { | ||
for (const key in asmVarValues) { | ||
const val = asmVarValues[key]; | ||
const re = new RegExp(`\\$${key}`, 'g'); | ||
this._lockingScriptAsm = this._lockingScriptAsm.replace(re, val); | ||
} | ||
} | ||
toASM() { | ||
@@ -29,0 +42,0 @@ if (this.lockingScript) { |
@@ -18,2 +18,5 @@ import { ABICoder, ABIEntity, FunctionCall, Script } from "./abi"; | ||
} | ||
export declare type AsmVarValues = { | ||
[key: string]: string; | ||
}; | ||
export declare class AbstractContract { | ||
@@ -29,2 +32,3 @@ static contractName: string; | ||
get txContext(): TxContext; | ||
replaceAsmVars(asmVarValues: AsmVarValues): void; | ||
run_verify(unlockingScriptASM: string, txContext?: TxContext): VerifyResult; | ||
@@ -31,0 +35,0 @@ private _dataLoad?; |
@@ -20,2 +20,6 @@ "use strict"; | ||
} | ||
// replace assembly variables with assembly values | ||
replaceAsmVars(asmVarValues) { | ||
this.scriptedConstructor.init(asmVarValues); | ||
} | ||
run_verify(unlockingScriptASM, txContext) { | ||
@@ -22,0 +26,0 @@ const txCtx = Object.assign({}, this._txContext || {}, txContext || {}); |
{ | ||
"name": "scryptlib", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -161,3 +161,14 @@ # scryptlib | ||
``` | ||
## Instantiate Inline Assembly Variables | ||
Assembly variables can be replaced with literal Script in ASM format using `replace()`. Each variable is prefixed by its unique scope, namely, the contract and the function it is under. | ||
```typescript | ||
const asmVars = { | ||
'contract1.function1.variable1': 'ff41', | ||
'contract2.function2.variable2': 'OP_4' | ||
}; | ||
instance.replaceAsmVars(asmVars); | ||
``` | ||
You could find more examples using `scryptlib` in the [boilerplate](https://github.com/scrypt-sv/boilerplate) repository. | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52034
1112
174