/
utxotxinputtype.go
67 lines (56 loc) · 1.56 KB
/
utxotxinputtype.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package dnaapi
import (
. "DNA_POW/common"
tx "DNA_POW/core/transaction"
"encoding/hex"
"fmt"
"github.com/yuin/gopher-lua"
)
const luaUTXOTxInputTypeName = "utxotxinput"
// Registers my person type to given L.
func RegisterUTXOTxInputType(L *lua.LState) {
mt := L.NewTypeMetatable(luaUTXOTxInputTypeName)
L.SetGlobal("utxotxinput", mt)
// static attributes
L.SetField(mt, "new", L.NewFunction(newUTXOTxInput))
// methods
L.SetField(mt, "__index", L.SetFuncs(L.NewTable(), utxotxinputMethods))
}
// Constructor
func newUTXOTxInput(L *lua.LState) int {
referIDStr := L.ToString(1)
referIdx := L.ToInt(2)
sequence := L.ToInt(3)
referIDSlice, _ := hex.DecodeString(referIDStr)
referIDSlice = BytesReverse(referIDSlice)
var referID Uint256
copy(referID[:], referIDSlice[0:32])
input := &tx.UTXOTxInput{
ReferTxID: referID,
ReferTxOutputIndex: uint16(referIdx),
Sequence: uint32(sequence),
}
ud := L.NewUserData()
ud.Value = input
L.SetMetatable(ud, L.GetTypeMetatable(luaUTXOTxInputTypeName))
L.Push(ud)
return 1
}
// Checks whether the first lua argument is a *LUserData with *UTXOTxInput and returns this *UTXOTxInput.
func checkUTXOTxInput(L *lua.LState, idx int) *tx.UTXOTxInput {
ud := L.CheckUserData(idx)
if v, ok := ud.Value.(*tx.UTXOTxInput); ok {
return v
}
L.ArgError(1, "UTXOTxInput expected")
return nil
}
var utxotxinputMethods = map[string]lua.LGFunction{
"get": utxotxinputGet,
}
// Getter and setter for the Person#Name
func utxotxinputGet(L *lua.LState) int {
p := checkUTXOTxInput(L, 1)
fmt.Println(p)
return 0
}