diff --git a/pkg/bytes/buffer.cell b/pkg/bytes/buffer.cell index ca11f6d..768353a 100644 --- a/pkg/bytes/buffer.cell +++ b/pkg/bytes/buffer.cell @@ -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 } diff --git a/pkg/math/bits/bits.cell b/pkg/math/bits/bits.cell index 25cf052..174f5a9 100644 --- a/pkg/math/bits/bits.cell +++ b/pkg/math/bits/bits.cell @@ -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]) @@ -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]) @@ -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, diff --git a/tests/examples/interface.cell b/tests/examples/interface.cell index 037f14b..14df941 100644 --- a/tests/examples/interface.cell +++ b/tests/examples/interface.cell @@ -1,3 +1,4 @@ + import ( "errors" "debug" @@ -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) diff --git a/tests/examples/xudt.cell b/tests/examples/xudt.cell index 20ade91..42fdab0 100644 --- a/tests/examples/xudt.cell +++ b/tests/examples/xudt.cell @@ -7,6 +7,8 @@ import ( "tx" "bytes" "encoding/binary" + "errors" + "blockchain" ) const ( @@ -97,7 +99,8 @@ type XudtCell table { func Inputs() []XudtCell { // todo - rawIns := tx.inputs() + raw := tx.inputs() + ins := []XudtCell{} return ins } @@ -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 @@ -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 @@ -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 @@ -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) {