tmp use PubK instead of Addr, Add test add genesis block

This commit is contained in:
arnaucube
2019-04-09 09:58:01 +02:00
parent 670b215e0a
commit 985f03bb14
4 changed files with 65 additions and 16 deletions

View File

@@ -1,25 +1,28 @@
package core
import "crypto/ecdsa"
type Input struct {
TxId Hash
Vout int // index of the output from the TxId
Value uint64
}
type Output struct {
Value uint64
}
// Tx holds the data structure of a transaction
type Tx struct {
From Address
To Address
From *ecdsa.PublicKey
To *ecdsa.PublicKey
InputCount uint64
Inputs []Input
Outputs []Output
Signature []byte
}
func NewTx(from, to Address, in []Input, out []Output) *Tx {
func NewTx(from, to *ecdsa.PublicKey, in []Input, out []Output) *Tx {
tx := &Tx{
From: from,
To: to,

View File

@@ -7,13 +7,17 @@ import (
)
func TestTx(t *testing.T) {
addr0 := Address(HashBytes([]byte("addr0")))
addr1 := Address(HashBytes([]byte("addr1")))
privK0, err := NewKey()
assert.Nil(t, err)
pubK0 := privK0.PublicKey
privK1, err := NewKey()
assert.Nil(t, err)
pubK1 := privK1.PublicKey
tx := NewTx(addr0, addr1, []Input{}, []Output{})
tx := NewTx(&pubK0, &pubK1, []Input{}, []Output{})
assert.Equal(t, tx.From, addr0)
assert.Equal(t, tx.To, addr1)
assert.Equal(t, tx.From, &pubK0)
assert.Equal(t, tx.To, &pubK1)
assert.True(t, CheckTx(tx))
}