diff --git a/pkg/ckb/syscalls.cell b/pkg/ckb/syscalls.cell index 567fb3c..e049bb1 100644 --- a/pkg/ckb/syscalls.cell +++ b/pkg/ckb/syscalls.cell @@ -122,17 +122,19 @@ func loadCellData(index uint32, source uint32) []byte { __slice_set_len(&data, size) return data } +// load cell data from cells grouped by script func loadInputCellData(index uint32) []byte { - return loadCellData(index, CKB_SOURCE_INPUT) + return loadCellData(index, CKB_SOURCE_GROUP_INPUT) } func loadOutputCellData(index uint32) []byte { - return loadCellData(index, CKB_SOURCE_OUTPUT) + return loadCellData(index, CKB_SOURCE_GROUP_OUTPUT) } func VMVersion() uint64 { return ckb_vm_version() } // load cell as CellOutput pattern +// equals load cell by field {capacity, lock, type} func inputCell(index uint) blockchain.CellOutput { data := make([]byte, SIZE_CELL, SIZE_CELL) ptr := __slice_get_ptr(&data) diff --git a/pkg/encoding/binary/binary.cell b/pkg/encoding/binary/binary.cell index 9563301..39cbbdc 100644 --- a/pkg/encoding/binary/binary.cell +++ b/pkg/encoding/binary/binary.cell @@ -4,6 +4,7 @@ import ( "errors" "io" "bytes" + "debug" ) type ByteOrder interface { @@ -204,5 +205,20 @@ func ReadUint32(r io.Reader, order ByteOrder) uint32 { if err.NotNone() { return uint32(0) } + // for i, v := range bs { + // debug.Printf("bs i %d", v) + // } return order.Uint32(bs) } + +func ReadUint64(r io.Reader, order ByteOrder) uint64 { + bs := make([]byte, 8) + for i, v := range bs { + debug.Printf("bs i %x", v) + } + n, err := io.ReadFull(r, bs) + if err.NotNone() { + return 0 + } + return order.Uint64(bs) +}