scryptlib
Advanced tools
Comparing version 0.2.8 to 0.2.9
@@ -33,8 +33,8 @@ import { ABICoder, ABIEntity, FunctionCall, Script } from "./abi"; | ||
run_verify(unlockingScriptASM: string, txContext?: TxContext): VerifyResult; | ||
private _dataLoad; | ||
set dataLoad(dataInHex: string | undefined | null); | ||
get dataLoad(): string | undefined | null; | ||
private _dataPart; | ||
set dataPart(dataInScript: Script | undefined); | ||
get dataPart(): Script | undefined; | ||
setDataPart(dataInHex: string): void; | ||
get codePart(): Script; | ||
get dataPart(): Script | undefined; | ||
} | ||
export declare function buildContractClass(desc: ContractDescription): any; |
@@ -9,4 +9,4 @@ "use strict"; | ||
let lsASM = this.scriptedConstructor.toASM(); | ||
if (this._dataLoad !== undefined && this._dataLoad !== null) { | ||
lsASM += ` OP_RETURN ${this._dataLoad}`; | ||
if (this._dataPart !== undefined && this._dataPart !== null) { | ||
lsASM += ` OP_RETURN ${this._dataPart}`; | ||
} | ||
@@ -39,22 +39,15 @@ return utils_1.bsv.Script.fromASM(lsASM.trim()); | ||
} | ||
set dataLoad(dataInHex) { | ||
if (dataInHex === undefined || dataInHex === null) { | ||
this._dataLoad = undefined; | ||
} | ||
else { | ||
this._dataLoad = dataInHex.trim(); | ||
} | ||
set dataPart(dataInScript) { | ||
throw new Error('Setter for dataPart is not available. Please use: setDataPart() instead'); | ||
} | ||
get dataLoad() { | ||
return this._dataLoad || null; | ||
get dataPart() { | ||
return this._dataPart !== undefined ? utils_1.bsv.Script.fromASM(this._dataPart) : undefined; | ||
} | ||
setDataPart(dataInHex) { | ||
// TODO: validate hex string | ||
this._dataPart = dataInHex.trim(); | ||
} | ||
get codePart() { | ||
return this.scriptedConstructor.lockingScript; | ||
} | ||
get dataPart() { | ||
if (this._dataLoad !== undefined && this._dataLoad !== null) { | ||
return utils_1.bsv.Script.fromASM(this._dataLoad); | ||
} | ||
return undefined; | ||
} | ||
} | ||
@@ -61,0 +54,0 @@ exports.AbstractContract = AbstractContract; |
@@ -1,1 +0,1 @@ | ||
export declare function serializeState(state: unknown): string; | ||
export declare function serializeState(state: Record<string, boolean | number | string>): string; |
@@ -9,2 +9,4 @@ "use strict"; | ||
const BN = utils_1.bsv.crypto.BN; | ||
// number of bytes to denote state length after serialization, exclusing varint prefix | ||
const STATE_LEN = 2; | ||
function serializeBool(flag) { | ||
@@ -39,2 +41,3 @@ return flag ? '01' : '00'; | ||
} | ||
// serialize contract state into Script ASM | ||
function serializeState(state) { | ||
@@ -49,3 +52,4 @@ const asms = []; | ||
}); | ||
const len = serializeInt(stateLen); | ||
// use fixed size (2 bytes) to denote state len | ||
const len = utils_1.num2bin(stateLen, STATE_LEN); | ||
asms.push(len); | ||
@@ -52,0 +56,0 @@ return asms.join(' '); |
{ | ||
"name": "scryptlib", | ||
"version": "0.2.8", | ||
"version": "0.2.9", | ||
"description": "Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -153,7 +153,13 @@ # scryptlib | ||
## Contracts with State | ||
sCrypt offers [stateful contracts](https://medium.com/xiaohuiliu/stateful-smart-contracts-on-bitcoin-sv-c24f83a0f783). `OP_RETURN` data of the contract locking script can be accessed by using an accessor named `dataLoad`, for example: | ||
sCrypt offers [stateful contracts](https://medium.com/xiaohuiliu/stateful-smart-contracts-on-bitcoin-sv-c24f83a0f783). `OP_RETURN` data of the contract locking script can be accessed by using an accessor named `dataPart`, for example: | ||
```typescript | ||
instance.dataLoad = dataInASM; | ||
const dataPart = instance.dataPart; | ||
const dataPartASM = instance.dataPart.toASM(); | ||
const dataPartHex = instance.dataPart.toHex(); | ||
// to set it using ASM | ||
instance.setDataPart(dataInASM); | ||
``` | ||
After that, the `instance.lockingScript` would include the dataLoad automatically. If you want to access the code part of the contract's locking script without `dataLoad` data, use: | ||
After that, the `instance.lockingScript` would include the data part automatically. | ||
If you want to access the code part of the contract's locking script without `dataPart` data, use: | ||
```typescript | ||
@@ -164,8 +170,2 @@ const codePart = instance.codePart; | ||
``` | ||
Also to access the data part (in `OP_RETURN`) of the contract locking script, use: | ||
```typescript | ||
const dataPart = instance.dataPart; | ||
const dataPartASM = instance.dataPart.toASM(); | ||
const dataPartHex = instance.dataPart.toHex(); | ||
``` | ||
@@ -172,0 +172,0 @@ ## Instantiate Inline Assembly Variables |
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
61121
1350