github.com/mavryk-network/mvgo@v1.19.9/rpc/doubleendorsement.go (about)

     1  // Copyright (c) 2020-2022 Blockwatch Data Inc.
     2  // Author: alex@blockwatch.cc
     3  
     4  package rpc
     5  
     6  import "github.com/mavryk-network/mvgo/mavryk"
     7  
     8  // Ensure DoubleEndorsement implements the TypedOperation interface.
     9  var _ TypedOperation = (*DoubleEndorsement)(nil)
    10  
    11  // DoubleEndorsement represents a double_endorsement_evidence operation
    12  type DoubleEndorsement struct {
    13  	Generic
    14  	OP1 InlinedEndorsement `json:"op1"`
    15  	OP2 InlinedEndorsement `json:"op2"`
    16  }
    17  
    18  // Costs returns operation cost to implement TypedOperation interface.
    19  func (d DoubleEndorsement) Costs() mavryk.Costs {
    20  	var burn int64
    21  	upd := d.Metadata.BalanceUpdates
    22  	// last item is accuser reward, rest is burned
    23  	for i, v := range upd {
    24  		if i == len(upd)-1 {
    25  			burn -= v.Amount()
    26  		} else {
    27  			burn += v.Amount()
    28  		}
    29  	}
    30  	return mavryk.Costs{
    31  		Burn: -burn,
    32  	}
    33  }