Skip to content

Commit

Permalink
fix load cell data for type script
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Sep 7, 2024
1 parent 6770683 commit f1f034e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/ckb/syscalls.cell
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions pkg/encoding/binary/binary.cell
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"io"
"bytes"
"debug"
)

type ByteOrder interface {
Expand Down Expand Up @@ -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)
}

0 comments on commit f1f034e

Please sign in to comment.