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

     1  // Copyright (c) 2022 Blockwatch Data Inc.
     2  // Author: alex@blockwatch.cc
     3  
     4  package rpc
     5  
     6  import (
     7  	"github.com/mavryk-network/mvgo/mavryk"
     8  	"github.com/mavryk-network/mvgo/micheline"
     9  )
    10  
    11  // Ensure TransferTicket implements the TypedOperation interface.
    12  var _ TypedOperation = (*TransferTicket)(nil)
    13  
    14  type TransferTicket struct {
    15  	Manager
    16  	Destination mavryk.Address `json:"destination"`
    17  	Entrypoint  string         `json:"entrypoint"`
    18  	Type        micheline.Prim `json:"ticket_ty"`
    19  	Contents    micheline.Prim `json:"ticket_contents"`
    20  	Ticketer    mavryk.Address `json:"ticket_ticketer"`
    21  	Amount      mavryk.Z       `json:"ticket_amount"`
    22  }
    23  
    24  // Costs returns operation cost to implement TypedOperation interface.
    25  func (t TransferTicket) Costs() mavryk.Costs {
    26  	res := t.Metadata.Result
    27  	cost := mavryk.Costs{
    28  		Fee:     t.Manager.Fee,
    29  		GasUsed: res.Gas(),
    30  	}
    31  	if !t.Result().IsSuccess() {
    32  		return cost
    33  	}
    34  	for _, v := range res.BalanceUpdates {
    35  		if v.Kind != CONTRACT {
    36  			continue
    37  		}
    38  		burn := v.Amount()
    39  		if burn >= 0 {
    40  			continue
    41  		}
    42  		cost.StorageBurn += -burn
    43  	}
    44  	return cost
    45  }