forked from gitchain/gitchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ndt.go
53 lines (42 loc) · 1.01 KB
/
ndt.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
//// Name Deallocation Transaction (NDT)
package transaction
import (
"encoding/gob"
"encoding/json"
"fmt"
"github.com/gitchain/gitchain/types"
)
func init() {
gob.Register(&NameDeallocation{})
}
const (
NAME_DEALLOCATION_VERSION = 1
)
type NameDeallocation struct {
Version uint32
Name string
}
func (tx *NameDeallocation) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]interface{}{
"Type": "Name Deallocation Tranasction",
"Version": tx.Version,
"Name": tx.Name,
})
}
func NewNameDeallocation(name string) (txn *NameDeallocation, err error) {
return &NameDeallocation{
Version: NAME_DEALLOCATION_VERSION,
Name: name}, nil
}
func (txn *NameDeallocation) Valid() bool {
return (txn.Version == NAME_ALLOCATION_VERSION && len(txn.Name) > 0)
}
func (txn *NameDeallocation) Encode() ([]byte, error) {
return encode(txn)
}
func (txn *NameDeallocation) Hash() types.Hash {
return hash(txn)
}
func (txn *NameDeallocation) String() string {
return fmt.Sprintf("NDT %s", txn.Name)
}