|
|
|
@ -15,7 +15,6 @@ const ( |
|
|
|
|
BLOCK |
|
|
|
|
CONTROL |
|
|
|
|
|
|
|
|
|
EXPERIMENT // Exist only for experiment setup
|
|
|
|
|
// TODO: add more types
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
@ -42,14 +41,6 @@ const ( |
|
|
|
|
STOP ControlMessageType = iota |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// The types of messages used for NODE/EXPERIMENT
|
|
|
|
|
type ExperimentMessageType int |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
UTXO_REQUEST ExperimentMessageType = iota |
|
|
|
|
UTXO_RESPONSE |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Constructs serialized transactions
|
|
|
|
|
func ConstructTransactionListMessage(transactions []*blockchain.Transaction) []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(common.NODE)}) |
|
|
|
@ -84,17 +75,6 @@ func ConstructStopMessage() []byte { |
|
|
|
|
return byteBuffer.Bytes() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Constructs utxo response message with serialized utxoPool to return
|
|
|
|
|
func ConstructUtxoResponseMessage(pool blockchain.UTXOPool) []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(common.NODE)}) |
|
|
|
|
byteBuffer.WriteByte(byte(EXPERIMENT)) |
|
|
|
|
byteBuffer.WriteByte(byte(UTXO_RESPONSE)) |
|
|
|
|
encoder := gob.NewEncoder(byteBuffer) |
|
|
|
|
|
|
|
|
|
encoder.Encode(pool) |
|
|
|
|
return byteBuffer.Bytes() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Constructs blocks sync message to send blocks to other nodes
|
|
|
|
|
func ConstructBlocksSyncMessage(blocks []blockchain.Block) []byte { |
|
|
|
|
byteBuffer := bytes.NewBuffer([]byte{byte(common.NODE)}) |
|
|
|
|