Skip to content

Commit

Permalink
fix ckb syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Sep 4, 2024
1 parent 122a98c commit 2f472a1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
27 changes: 21 additions & 6 deletions pkg/ckb/syscalls.cell
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ const (
SIZE_DATA = 256 * 1024
)

const (
CKB_SOURCE_INPUT = 1
CKB_SOURCE_OUTPUT = 2
CKB_SOURCE_CELL_DEP = 3
CKB_SOURCE_HEADER_DEP = 4
CKB_SOURCE_GROUP_INPUT = 72057594037927937 // 0x0100000000000001
CKB_SOURCE_GROUP_OUTPUT = 72057594037927938 // 0x0100000000000002
)

func loadTxHash() blockchain.Byte32 {
data := make([]byte, SIZE_H256, SIZE_H256)
ptr := __slice_get_ptr(data)
Expand All @@ -28,7 +37,7 @@ func loadTxHash() blockchain.Byte32 {
}
func loadTx() []byte {
data := make([]byte, SIZE_TX, SIZE_TX)
ptr := __slice_get_ptr(data)
ptr := __slice_get_ptr(&data)
size := SIZE_MAX
err := ckb_load_transaction(ptr, &size, 0)
if err != CKB_SUCCESS {
Expand All @@ -44,7 +53,7 @@ func loadTx() []byte {
}
func loadScriptHash() blockchain.Byte32 {
data := make([]byte, SIZE_H256, SIZE_H256)
ptr := __slice_get_ptr(data)
ptr := __slice_get_ptr(&data)
size := SIZE_MAX
err := ckb_load_script_hash(ptr, &size, 0)
if err != CKB_SUCCESS {
Expand All @@ -69,7 +78,7 @@ func loadScript() blockchain.Script {
}
func loadInput(index uint32, source uint32) []byte {
data := make([]byte, SIZE_CELL, SIZE_CELL)
ptr := __slice_get_ptr(data)
ptr := __slice_get_ptr(&data)
size := SIZE_MAX
err := ckb_load_input(ptr, &size, 0, index, source)
if err != CKB_SUCCESS {
Expand All @@ -80,7 +89,7 @@ func loadInput(index uint32, source uint32) []byte {
// header is a sub-structure of block and UncleBlock
func loadHeader(index uint32, source uint32) []byte {
data := make([]byte, SIZE_HEADER, SIZE_HEADER)
ptr := __slice_get_ptr(data)
ptr := __slice_get_ptr(&data)
size := SIZE_MAX
err := ckb_load_header(ptr, &size, 0, index, source)
if err != CKB_SUCCESS {
Expand All @@ -92,7 +101,7 @@ func loadHeader(index uint32, source uint32) []byte {
// func load_witness(addr uintptr, len uint64, offset uint, index uint, source uint) int
func loadWitness(index uint32, source uint32) []byte {
data := make([]byte, SIZE_WITNESS, SIZE_WITNESS)
ptr := __slice_get_ptr(data)
ptr := __slice_get_ptr(&data)
size := SIZE_MAX
err := ckb_load_witness(ptr, &size, 0, index, source)
if err != CKB_SUCCESS {
Expand All @@ -104,7 +113,7 @@ func loadWitness(index uint32, source uint32) []byte {
// func load_cell_data(addr uintptr, len uint64, offset uint, index uint, source uint) int
func loadCellData(index uint32, source uint32) []byte {
data := make([]byte, SIZE_DATA, SIZE_DATA)
ptr := __slice_get_ptr(data)
ptr := __slice_get_ptr(&data)
size := SIZE_MAX
err := ckb_load_cell_data(ptr, &size, 0, index, source)
if err != CKB_SUCCESS {
Expand All @@ -113,6 +122,12 @@ func loadCellData(index uint32, source uint32) []byte {
__slice_set_len(&data, size)
return data
}
func loadInputCellData(index uint32) []byte {
return loadCellData(index, CKB_SOURCE_INPUT)
}
func loadOutputCellData(index uint32) []byte {
return loadCellData(index, CKB_SOURCE_OUTPUT)
}
func VMVersion() uint64 {
return ckb_vm_version()
}
Expand Down
11 changes: 7 additions & 4 deletions tests/examples/sudt.cell
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import "debug"
import "tx"
import "cell"
import (
"debug"
"tx"
"ckb"
)

func main() {
// tx.scriptVerify()
script := ckb.loadScript()
// ckb.scriptVerify(script)
// isOwnerMode return a bool value:
// true - Indicate that the verification was successful and the device owner mode has been successfully set.
// false - Means that either the verification process failed or the device owner mode has not been set.
Expand Down
8 changes: 4 additions & 4 deletions tests/stdlib/ckb-test.cell
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ func main() {
ckb.loadScript()

CKB_SOURCE_INPUT := 1
ckb.loadInput(0, CKB_SOURCE_INPUT)
ckb.loadHeader(0, CKB_SOURCE_INPUT)
ckb.loadWitness(0, CKB_SOURCE_INPUT)
ckb.loadCellData(0, CKB_SOURCE_INPUT)
ckb.loadInput(0, ckb.CKB_SOURCE_INPUT)
ckb.loadHeader(0, ckb.CKB_SOURCE_INPUT)
ckb.loadWitness(0, ckb.CKB_SOURCE_INPUT)
ckb.loadCellData(0, ckb.CKB_SOURCE_INPUT)

ckb.VMVersion()
return 0
Expand Down

0 comments on commit 2f472a1

Please sign in to comment.