Skip to content

Commit

Permalink
fix stdlib and example, type cast
Browse files Browse the repository at this point in the history
  • Loading branch information
douyixuan committed Aug 28, 2024
1 parent 2ce91e1 commit 878344a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/bytes/buffer.cell
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (b *Buffer) empty() bool {

func (b *Buffer) Reset() {
b.buf = []byte{}
b.off = 0
b.off = uint32(0)
b.lastRead = opInvalid
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/math/bits/bits.cell
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Len16(v uint16) int64 {
var n int64
x := v
if x >= uint16(1<<8) {
x = x >> 8
x = x >> uint16(8)
n = 8
}
return n + int64(len8tab[x])
Expand All @@ -104,11 +104,11 @@ func Len32(v uint32) int64 {
var n int64
x := v
if x >= uint32(1<<16) {
x = x >> 16
x = x >> uint32(16)
n = 16
}
if x >= uint32(1<<8) {
x = x >> 8
x = x >> uint32(8)
n = n + 8
}
return n + int64(len8tab[x])
Expand Down Expand Up @@ -167,7 +167,7 @@ func Len(x uint64) int64 {

const deBruijn64 = 0x03f79d71b4ca8b09

var deBruijn64tab = [64]byte{
var deBruijn64tab = [64]uint64{
0, 1, 56, 2, 57, 49, 28, 3, 61, 58, 42, 50, 38, 29, 17, 4,
62, 47, 59, 36, 45, 43, 51, 22, 53, 39, 33, 30, 24, 18, 12, 5,
63, 55, 48, 27, 60, 41, 37, 16, 46, 35, 44, 21, 52, 32, 23, 11,
Expand Down
5 changes: 3 additions & 2 deletions tests/examples/interface.cell
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import (
"errors"
"debug"
Expand All @@ -13,8 +14,8 @@ func (b *Demo) ed() uint32 {
return b.end
}
func (b *Demo) reset() {
b.start = 0
b.end = 0
b.start = uint32(0)
b.end = uint32(0)
}
type Range interface {
st() (uint32, error)
Expand Down
33 changes: 23 additions & 10 deletions tests/examples/xudt.cell
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"tx"
"bytes"
"encoding/binary"
"errors"
"blockchain"
)

const (
Expand Down Expand Up @@ -97,7 +99,8 @@ type XudtCell table {

func Inputs() []XudtCell {
// todo
rawIns := tx.inputs()
raw := tx.inputs()

ins := []XudtCell{}
return ins
}
Expand Down Expand Up @@ -132,13 +135,23 @@ func checkCellsTypeHash(cells []XudtCell, args string) bool {
}
return false
}

func loadExtensionScripts() []cell.Script {
type CellScript table {
codeHash string // size == 32byte
hashType byte
args string
}
func loadExtensionScripts() []CellScript {
// todo
return []cell.Script{}
return []CellScript{}
}

func loadScript() CellScript {
raw := tx.checkedLoadScript()
var ret CellScript
return ret
}
func main() {
script := tx.checkedLoadScript()
script := loadScript()
ok := tx.scriptVerify()
ins := Inputs()
args := script.args
Expand All @@ -148,16 +161,16 @@ func main() {
// owner mode checking
var owner_mode bool
if owner_mode_for_input_lock && owner_mode == false {
owner_mode = checkInputLockHash(ins, args[0:32])
owner_mode = checkInputLockHash(ins, args[FLAGS_SIZE:tx.BLAKE2B_BLOCK_SIZE+FLAGS_SIZE])
}

if owner_mode_for_input_type && owner_mode == false {
owner_mode = checkCellsTypeHash(ins, args[0:32])
owner_mode = checkCellsTypeHash(ins, args[FLAGS_SIZE:tx.BLAKE2B_BLOCK_SIZE+FLAGS_SIZE])
}

outs := Outputs()
if owner_mode_for_output_type && owner_mode == false {
owner_mode = checkCellsTypeHash(outs, args[0:32])
owner_mode = checkCellsTypeHash(outs, args[FLAGS_SIZE:tx.BLAKE2B_BLOCK_SIZE+FLAGS_SIZE])
}

// parse xUDT args
Expand Down Expand Up @@ -208,7 +221,7 @@ func main() {
}

// decode ownerScript raw bytes to Script
var ownerScript cell.Script
var ownerScript CellScript
err := tx.executeFunc(ownerScriptHash, ownerScript.hashType, "validate", owner_mode, 0, ownerScript.args)
if err == SUCCESS {
owner_mode = true
Expand Down Expand Up @@ -237,7 +250,7 @@ func main() {
if flags == XUDTFlagsPlain {
return SUCCESS
}
// todo: decode extension scripts

extensionScripts := loadExtensionScripts()
// execute all scripts
for i, script := range(extensionScripts) {
Expand Down

0 comments on commit 878344a

Please sign in to comment.