Smartcontract (#39)

* deleted transfer_output added asset type and transaction result to core

* removed writing 0x00 when buffer length is 0

* Refactored emit into VM package + moved tx to own package.

* implemented transaction along with claimTransaction.

* refactored naming of transaction + added decode address for uint160 types

* removed unnecessary folder and files.

* transaction/smartcontract logic

* bumped version 0.24.0
This commit is contained in:
Anthony De Meulemeester 2018-03-04 14:56:49 +01:00 committed by GitHub
parent 42195b1af4
commit 1a1a19da7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 1066 additions and 170 deletions

View file

@ -8,6 +8,7 @@ import (
"io"
"log"
"github.com/CityOfZion/neo-go/pkg/core/transaction"
"github.com/CityOfZion/neo-go/pkg/util"
)
@ -26,12 +27,12 @@ type BlockBase struct {
Index uint32
// Random number also called nonce
ConsensusData uint64
// contract addresss of the next miner
// Contract addresss of the next miner
NextConsensus util.Uint160
// fixed to 1
_ uint8 // padding
// Script used to validate the block
Script *Witness
Script *transaction.Witness
}
// DecodeBinary implements the payload interface.
@ -66,11 +67,11 @@ func (b *BlockBase) DecodeBinary(r io.Reader) error {
return fmt.Errorf("format error: padding must equal 1 got %d", padding)
}
b.Script = &Witness{}
b.Script = &transaction.Witness{}
return b.Script.DecodeBinary(r)
}
// Hash return the hash of the block.
// Hash returns the hash of the block.
// When calculating the hash value of the block, instead of calculating the entire block,
// only first seven fields in the block head will be calculated, which are
// version, PrevBlock, MerkleRoot, timestamp, and height, the nonce, NextMiner.
@ -158,7 +159,7 @@ func (h *Header) EncodeBinary(w io.Writer) error {
type Block struct {
BlockBase
// transaction list
Transactions []*Transaction
Transactions []*transaction.Transaction
}
// Header returns a pointer to the head of the block (BlockHead).
@ -171,13 +172,13 @@ func (b *Block) Header() *Header {
// Verify the integrity of the block.
func (b *Block) Verify(full bool) bool {
// The first TX has to be a miner transaction.
if b.Transactions[0].Type != MinerTX {
if b.Transactions[0].Type != transaction.MinerType {
return false
}
// If the first TX is a minerTX then all others cant.
for _, tx := range b.Transactions[1:] {
if tx.Type == MinerTX {
if tx.Type == transaction.MinerType {
return false
}
}
@ -202,9 +203,9 @@ func (b *Block) DecodeBinary(r io.Reader) error {
}
lentx := util.ReadVarUint(r)
b.Transactions = make([]*Transaction, lentx)
b.Transactions = make([]*transaction.Transaction, lentx)
for i := 0; i < int(lentx); i++ {
tx := &Transaction{}
tx := &transaction.Transaction{}
if err := tx.DecodeBinary(r); err != nil {
return err
}