-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmetahash_lib.go
More file actions
105 lines (84 loc) · 2.1 KB
/
metahash_lib.go
File metadata and controls
105 lines (84 loc) · 2.1 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package metahash_lib
import (
"fmt"
"log"
"math/big"
)
// https://support.metahash.org/hc/ru/articles/360002712193
// https://support.metahash.org/hc/ru/articles/360003271694
// http://developers.metahash.org
type Address string
type PrivateKey string
type PublicKey string
type Sign string
var Logger = (*log.Logger)(nil) //log.New(os.Stderr, "", log.LstdFlags)
type MetahashKey interface {
MetahashPublic
Private() PrivateKey
Sign(data []byte) (Sign, error)
}
func NewKey() (MetahashKey, error) {
return newKeyV1()
}
func CreateKey(private PrivateKey) (MetahashKey, error) {
return createKeyV1(private)
}
type MetahashPublic interface {
Public() PublicKey
Veriff(data []byte, sign Sign) (bool, error)
Address() Address
}
func CreatePublic(public PublicKey) (MetahashPublic, error) {
return createPublicV1(public)
}
type Transaction struct {
To Address
Value *big.Int
//Fee *big.Int // not implemented yet
Nonce *big.Int
//Data string // not implemented yet
}
type Balance struct {
Address Address
Received *big.Int
Spent *big.Int
CountReceived int
CountSpent int
BlockNumber int
CurrentBlock int
}
type HistoryRecs []HistoryRec
type HistoryRec struct {
From Address `json:"from"`
To Address `json:"to"`
Value *big.Int `json:"value"`
TxHash TxHash `json:"transaction"`
}
type TxData struct {
Transaction HistoryRec
}
type TxHash string
type MetahashNetwork interface {
MetahashNetworkPublic
MetahashNetworkDev
Transaction(*Transaction) (TxHash, error)
}
type MetahashNetworkPublic interface {
Balance(Address) (*Balance, error)
History(Address) (*HistoryRecs, error)
GetTx(TxHash) (*HistoryRec, error)
}
type MetahashNetworkDev interface {
Add(Address) error
}
func NewMetahashNetwork(mk MetahashKey, net NetworkType) (MetahashNetwork, error) {
return newMetahashNetworkV1(mk, net)
}
func NewMetahashNetworkPublic(mp MetahashPublic, net NetworkType) (MetahashNetworkPublic, error) {
return newMetahashNetworkPublicV1(mp, net)
}
func logPrintf(format string, v ...interface{}) {
if Logger != nil {
Logger.Output(2, fmt.Sprintf(format, v...))
}
}