Skip to content

Commit

Permalink
Merge pull request #73 from sCrypt-Inc/develop
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
zhfnjust authored Mar 6, 2021
2 parents 355974e + fe7f157 commit 193bb0a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 5 deletions.
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,44 @@ The compiler outputs results in a JSON file. It’s a representation used to bui

```json
{
"version": 2, // version of description file, you can look at VERSIONLOG.md to see what has changed in each version
"compilerVersion": "0.1.0+commit.312f643", // version of compiler used to produce this file
"contract": "DemoP2PKH", // name of the contract
"md5": "01234...", // md5 of the contract source code file
"structs": [ // All structures defined in the contracts, including dependent contracts
{
"name": "Person",
"params": [
{
"name": "age",
"type": "Age",
"finalType": "int"
},
{
"name": "name",
"type": "Name",
"finalType": "bytes"
},
{
"name": "token",
"type": "Token",
"finalType": "int"
}
]
},
...
],
"alias": [ // All type alias defined in the contracts, including dependent contracts
{
"name": "Male",
"type": "Person"
},
{
"name": "Female",
"type": "Person"
},
...
],
"abi": [ // ABI of the contract: interfaces of its public functions and constructor.
{
"type": "constructor",
Expand All @@ -52,9 +87,20 @@ The compiler outputs results in a JSON file. It’s a representation used to bui
}
]
},

...
],
"asm": "$pubKeyHash OP_OVER OP_HASH160 ..." // locking script of the contract in ASM format, including placeholders for constructor parameters
"file": "file:///C:/Users/sCrypt/code/project/mainContract.scrypt", //file uri of the main contract source code file.
"asm": "$pubKeyHash OP_OVER OP_HASH160 ...", // locking script of the contract in ASM format, including placeholders for constructor parameters
"sources": [ // all compiled sources file related to the contract
"std",
"C:\\Users\\sCrypt\\code\\project\\util.scrypt"
"C:\\Users\\sCrypt\\code\\project\\contract.scrypt"
],
"sourceMap": [ //sourceMap, you need to enable sourceMap setting in sCrypt IDE, default is disabled.
"0:76:53:76:58",
...
]
}
```

Expand All @@ -73,6 +119,9 @@ There are two ways to generate this file (named as `xxx_desc.json`):
},
{
desc: true // set this flag to be `true` to get the description file output
asm: true // set this flag to be `true` to get the asm file output
optimize: false //set this flag to be `true` to get optimized asm opcode
sourceMap: true //set this flag to be `true` to get source map
}
);
```
Expand Down Expand Up @@ -111,10 +160,16 @@ Note that `parameters` in both constructor and function call are mapped to sCryp

* `boolean`: mapped to sCrypt `bool`
* `number`: mapped to sCrypt `int`
* `new Byte(x)` / `new Bytes(x)` / `new Sig(x)` / `new PubKey(x)` / `new Ripemd160(x)` / … : mapped to sCrypt `byte` / `bytes` / `Sig` / `PubKey` / `Ripemd160` / … , where `x` is hex string
* `new Int(x)`/ `new Bool(x)` / `new Bytes(x)` / `new Sig(x)` / `new PubKey(x)` / `new Ripemd160(x)` / … : mapped to sCrypt `int` / `bool` / `bytes` / `Sig` / `PubKey` / `Ripemd160` / … , where `x` is hex string

In this way, the type of parameters could be checked and potential bugs can be detected before running.

Composite types, including structs and type aliases, are dynamically generated by `buildTypeClasses`.

```typescript
const {Person, Male, Female} = buildTypeClasses(JSON.parse(descFileContent));
```

## Local Unit Tests

A useful method `verify(txContext)` is provided for each contract function call. It would execute the function call with the given context locally. The `txContext` argument provides some context information of the current transaction, **needed only if signature is checked inside the contract**.
Expand Down Expand Up @@ -180,5 +235,5 @@ const asmVars = {
instance.replaceAsmVars(asmVars);
```

You could find more examples using `scryptlib` in the [boilerplate](https://github.com/scrypt-sv/boilerplate) repository.
You could find more examples using `scryptlib` in the [boilerplate](https://github.com/sCrypt-Inc/boilerplate) repository.

4 changes: 2 additions & 2 deletions VERSIONLOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

## version = 1

* Add SourceMap
* Add `sourceMap`, `structs`, `file`, `version`

## version = 2

* Add type alias
* Add `alias`

0 comments on commit 193bb0a

Please sign in to comment.