forked from hacash/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.go
executable file
·35 lines (31 loc) · 958 Bytes
/
transaction.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
package transactions
import (
"fmt"
"github.com/hacash/core/interfaces"
)
////////////////////////////////////////////////////////////////////////
func NewTransactionByType(ty uint8) (interfaces.Transaction, error) {
switch ty {
//////////////////// TRANSATION ////////////////////
case 0:
return new(Transaction_0_Coinbase), nil
case 1:
return new(Transaction_1_DO_NOT_USE_WITH_BUG), nil // [signed bug, obsolete!!!]
case 2:
return new(Transaction_2_Simple), nil
//////////////////// END ////////////////////
}
return nil, fmt.Errorf("Cannot find Transaction type of " + string(ty))
}
func ParseTransaction(buf []byte, seek uint32) (interfaces.Transaction, uint32, error) {
if seek >= uint32(len(buf)) {
return nil, 0, fmt.Errorf("buf length over range")
}
ty := uint8(buf[seek])
var trx, e1 = NewTransactionByType(ty)
if e1 != nil {
return nil, 0, e1
}
var mv, err = trx.Parse(buf, seek+1)
return trx, mv, err
}