-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathblockchain-datastructures.go
80 lines (62 loc) · 2.56 KB
/
blockchain-datastructures.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
68
69
70
71
72
73
74
75
76
77
78
79
80
// jeffCoin 1. BLOCKCHAIN blockchain-datastructures.go
package blockchain
// BLOCK & BLOCKCHAIN ****************************************************************************************************
// blockStruct is your block
type blockStruct struct {
BlockID int64 `json:"blockID"`
Timestamp string `json:"timestamp"`
Transactions []transactionStruct `json:"transactions"`
Hash string `json:"hash"`
PrevHash string `json:"prevhash"`
Difficulty int `json:"difficulty"`
Nonce string `json:"nonce"`
}
// pendingBlock - Receiving transactions and not part of chain
var pendingBlock = blockStruct{}
// lockedBlock - Going to be added to the chain (No more transactions)
var lockedBlock = blockStruct{}
// blockchainSlice is my block type
type blockchainSlice []blockStruct
// blockchain is the blockchain
var blockchain = blockchainSlice{}
// TRANSACTIONS **********************************************************************************************************
// transactionStruct is your transaction - To be placed in a block
type transactionStruct struct {
TxID int64 `json:"txID"`
Inputs []inputsStruct `json:"inputs"`
Outputs []outputsStruct `json:"outputs"`
}
// transactions is a transaction
var transaction = transactionStruct{}
// inputsStruct is a transaction input
type inputsStruct struct {
RefTxID int64 `json:"refTxID"`
InPubKey string `json:"inPubKey"`
Signature string `json:"signature"`
}
// outputsStruct is a transaction output
type outputsStruct struct {
OutPubKey string `json:"outPubKey"`
Value int64 `json:"value"`
}
// UNSPENT OUTPUT ********************************************************************************************************
type unspentOutputStruct struct {
TxID int64 `json:"txID"`
Value int64 `json:"value"`
}
// TRANSACTION REQUESTS **************************************************************************************************
// txRequestMessageSignedStruct - Signed
type txRequestMessageSignedStruct struct {
TxRequestMessage txRequestMessageStruct `json:"txRequestMessage"`
Signature string `json:"signature"`
}
// txRequestMessageStruct - Unsigned
type txRequestMessageStruct struct {
SourceAddress string `json:"sourceAddress"`
Destinations []destinationStruct `json:"destinations"`
}
// destinationStruct for multiple destinations
type destinationStruct struct {
DestinationAddress string `json:"destinationAddress"`
Value int64 `json:"value"`
}