Skip to content

Commit 687d3ea

Browse files
committed
support ckb.loadTxHash
1 parent 671aa32 commit 687d3ea

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

pkg/ckb/native.cell

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package ckb
22

33
extern (
4+
func __slice_get_ptr(s []byte) uintptr
5+
46
// reference from ckb_syscall_apis.h
57
func ckb_load_tx_hash(addr uintptr, len uint64, offset uint) int
68
func ckb_load_transaction(addr uintptr, len uint64, offset uint) int
@@ -20,3 +22,7 @@ extern (
2022
// todo
2123
// func ckb_exec_cell(code_hash *byte, hash_type uint8, offset uint32, length uint8, argc int, argv []*byte) int
2224
)
25+
26+
const (
27+
CKB_SUCCESS = 0
28+
)

pkg/ckb/syscalls.cell

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package ckb
2+
3+
import (
4+
// "blockchain"
5+
)
6+
7+
const SIZE_H256 = 32
8+
9+
func loadTxhash() []byte {
10+
hash := make([]byte, SIZE_H256, SIZE_H256)
11+
ptr := __slice_get_ptr(hash)
12+
err := ckb_load_tx_hash(ptr, SIZE_H256, 0)
13+
if err != CKB_SUCCESS {
14+
return []byte{}
15+
}
16+
// var a blockchain.Byte32
17+
return hash
18+
}

0 commit comments

Comments
 (0)