OSDN Git Service

optimise
authoroys <oys@oysdeMBP.localdomain>
Sat, 6 Jul 2019 03:14:57 +0000 (11:14 +0800)
committeroys <oys@oysdeMBP.localdomain>
Sat, 6 Jul 2019 03:14:57 +0000 (11:14 +0800)
protocol/state/vote_result.go
protocol/validation/block.go

index 9b0a0fc..f66ca73 100644 (file)
@@ -70,9 +70,8 @@ func (a SortByAmount) Less(i, j int) bool { return a[i].Amount < a[j].Amount }
 func CalCoinbaseReward(block *types.Block) (*CoinbaseReward, error) {
        var coinbaseReceiver []byte
        if len(block.Transactions) > 0 && len(block.Transactions[0].InputIDs) > 0 && len(block.Transactions[0].Outputs) > 0 {
-               coinbaseTx := block.Transactions[0]
-               if _, ok := coinbaseTx.Entries[coinbaseTx.InputIDs[0]].(*bc.Coinbase); ok {
-                       coinbaseReceiver = coinbaseTx.Outputs[0].ControlProgram()
+               if block.Transactions[0].Inputs[0].InputType() == types.CoinbaseInputType {
+                       coinbaseReceiver = block.Transactions[0].Outputs[0].ControlProgram()
                }
        }
 
index 3b98274..9c1ad99 100644 (file)
@@ -49,14 +49,13 @@ func checkCoinbaseTx(b *bc.Block, rewards []state.CoinbaseReward) error {
 
        rewards = append([]state.CoinbaseReward{state.CoinbaseReward{Amount: uint64(0)}}, rewards...)
        for i, output := range tx.TxHeader.ResultIds {
-               e, ok := tx.Entries[*output].(*bc.IntraChainOutput)
-               if !ok {
-                       return errors.Wrapf(bc.ErrEntryType, "entry %x has unexpected type %T", output.Bytes(), output)
+               out, err := tx.IntraChainOutput(*output)
+               if err != nil {
+                       return err
                }
-               coinbaseAmount := e.Source.Value.Amount
 
-               if rewards[i].Amount != coinbaseAmount {
-                       return errors.Wrapf(ErrWrongCoinbaseTransaction, "dismatch output amount, got:%d, want:%d", coinbaseAmount, rewards[i].Amount)
+               if rewards[i].Amount != out.Source.Value.Amount {
+                       return errors.Wrapf(ErrWrongCoinbaseTransaction, "dismatch output amount, got:%d, want:%d", out.Source.Value.Amount, rewards[i].Amount)
                }
        }
        return nil