}
type Coinbase struct {
- Program *Program `protobuf:"bytes,1,opt,name=program" json:"program,omitempty"`
- BlockId *Hash `protobuf:"bytes,2,opt,name=block_id,json=blockId" json:"block_id,omitempty"`
- ExtHash *Hash `protobuf:"bytes,3,opt,name=ext_hash,json=extHash" json:"ext_hash,omitempty"`
- WitnessArguments [][]byte `protobuf:"bytes,4,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
- WitnessAnchoredId *Hash `protobuf:"bytes,5,opt,name=witness_anchored_id,json=witnessAnchoredId" json:"witness_anchored_id,omitempty"`
+ Program *Program `protobuf:"bytes,1,opt,name=program" json:"program,omitempty"`
+ BlockId *Hash `protobuf:"bytes,2,opt,name=block_id,json=blockId" json:"block_id,omitempty"`
+ ExtHash *Hash `protobuf:"bytes,3,opt,name=ext_hash,json=extHash" json:"ext_hash,omitempty"`
+ WitnessArguments [][]byte `protobuf:"bytes,4,rep,name=witness_arguments,json=witnessArguments,proto3" json:"witness_arguments,omitempty"`
}
func (m *Coinbase) Reset() { *m = Coinbase{} }
return nil
}
-func (m *Coinbase) GetWitnessAnchoredId() *Hash {
- if m != nil {
- return m.WitnessAnchoredId
- }
- return nil
-}
-
type Output struct {
Source *ValueSource `protobuf:"bytes,1,opt,name=source" json:"source,omitempty"`
ControlProgram *Program `protobuf:"bytes,2,opt,name=control_program,json=controlProgram" json:"control_program,omitempty"`
Hash block_id = 2;
Hash ext_hash = 3;
repeated bytes witness_arguments = 4;
- Hash witness_anchored_id = 5;
}
message Output {
--- /dev/null
+package bc
+
+import "io"
+
+func (Coinbase) typ() string { return "coinbase1" }
+func (n *Coinbase) writeForHash(w io.Writer) {
+ mustWriteForHash(w, n.Program)
+ mustWriteForHash(w, n.BlockId)
+}
+
+// NewCoinbase creates a new Coinbase.
+func NewCoinbase(p *Program, trID *Hash) *Coinbase {
+ return &Coinbase{
+ Program: p,
+ BlockId: trID,
+ }
+}
+++ /dev/null
-package validation
-
-import (
- "testing"
-
- "github.com/bytom/protocol/bc"
- "github.com/bytom/protocol/bc/legacy"
-)
-
-func TestFuzzAssetIdNilPointer(t *testing.T) {
- const (
- blockchainID = `50935a092ffad7ec9fbac4f4486db6c3b8cd5b9f51cf697248584dde286a7220`
- input = `07300730303030303030000001302b3030303030303030303030303030303030303030303030303030303030303030303030303030303030303000253030303030303030303030303030303030303030303030303030303030303030303030303000`
- )
-
- var testBlockchainID bc.Hash
- err := testBlockchainID.UnmarshalText([]byte(blockchainID))
- if err != nil {
- t.Fatal(err)
- }
-
- var tx legacy.Tx
- err = tx.UnmarshalText([]byte(input))
- if err != nil {
- t.Fatal(err)
- }
-
- ValidateTx(tx.Tx, testBlockchainID)
-}
// the transaction graph when validating entries.
type validationState struct {
// The ID of the blockchain
- blockchainID bc.Hash
+ block *bc.Block
// The enclosing transaction object
tx *bc.Tx
}
case *bc.Issuance:
- if *e.WitnessAssetDefinition.InitialBlockId != vs.blockchainID {
- return errors.WithDetailf(errWrongBlockchain, "current blockchain %x, asset defined on blockchain %x", vs.blockchainID.Bytes(), e.WitnessAssetDefinition.InitialBlockId.Bytes())
- }
-
computedAssetID := e.WitnessAssetDefinition.ComputeAssetID()
if computedAssetID != *e.Value.AssetId {
return errors.WithDetailf(errMismatchedAssetID, "asset ID is %x, issuance wants %x", computedAssetID.Bytes(), e.Value.AssetId.Bytes())
}
// ValidateTx validates a transaction.
-func ValidateTx(tx *bc.Tx, initialBlockID bc.Hash) (*uint64, error) {
+func ValidateTx(tx *bc.Tx, block *bc.Block) (*uint64, error) {
//TODO: handle the gas limit
vs := &validationState{
- blockchainID: initialBlockID,
- tx: tx,
- entryID: tx.ID,
+ block: block,
+ tx: tx,
+ entryID: tx.ID,
gas: &gasState{
gasLeft: defaultGasLimit,
},
},
},
{
- desc: "wrong blockchain",
- f: func() {
- vs.blockchainID = *newHash(2)
- },
- err: errWrongBlockchain,
- },
- {
desc: "issuance program failure",
f: func() {
iss := txIssuance(t, tx, 0)
fixture = sample(t, nil)
tx = legacy.NewTx(*fixture.tx).Tx
vs = &validationState{
- blockchainID: fixture.initialBlockID,
- tx: tx,
- entryID: tx.ID,
+ block: nil,
+ tx: tx,
+ entryID: tx.ID,
gas: &gasState{
gasLeft: uint64(1000),
gasUsed: 0,
tx.Inputs[0].TypedInput.(*legacy.IssuanceInput).Nonce = nil
})
- _, err := ValidateTx(legacy.MapTx(&tx.TxData), bc.EmptyStringHash)
+ _, err := ValidateTx(legacy.MapTx(&tx.TxData), nil)
if errors.Root(err) != bc.ErrMissingEntry {
t.Fatalf("got %s, want %s", err, bc.ErrMissingEntry)
}