github.com/mavryk-network/mvgo@v1.19.9/micheline/ticket.go (about)

     1  // Copyright (c) 2020-2021 Blockwatch Data Inc.
     2  // Author: alex@blockwatch.cc
     3  
     4  package micheline
     5  
     6  import "github.com/mavryk-network/mvgo/mavryk"
     7  
     8  // Wraps ticket value type into type structure that is compatible
     9  // with ticket values. This is necessary because T_TICKET uses an
    10  // implicit structure (extra fields amount, ticketer) in addition
    11  // to the defined value.
    12  func TicketType(t Prim) Type {
    13  	tt := t.Clone()
    14  	if len(tt.Anno) == 0 || tt.Anno[0] == "" {
    15  		tt.Anno = []string{":value"}
    16  		switch tt.Type {
    17  		case PrimNullary, PrimUnary, PrimBinary:
    18  			tt.Type++
    19  		}
    20  	}
    21  	return Type{NewPairType(
    22  		NewPrim(T_ADDRESS, ":ticketer"),
    23  		NewPairType(
    24  			tt,
    25  			NewPrim(T_INT, ":amount"),
    26  		),
    27  	)}
    28  }
    29  
    30  // Wraps ticket content into structure that is compatible
    31  // with ticket type. This is necessary for transfer_ticket calls which
    32  // use explicit fields for value, amount and ticketer.
    33  func TicketValue(v Prim, ticketer mavryk.Address, amount mavryk.Z) Prim {
    34  	return NewPair(
    35  		NewBytes(ticketer.EncodePadded()),
    36  		NewPair(v, NewNat(amount.Big())),
    37  	)
    38  }