github.com/NpoolPlatform/chain-middleware@v0.0.0-20240228100535-eb1bcf896eb9/pkg/db/ent/schema/tran.go (about)

     1  package schema
     2  
     3  import (
     4  	"entgo.io/ent"
     5  	"entgo.io/ent/dialect"
     6  	"entgo.io/ent/schema/field"
     7  	"github.com/NpoolPlatform/chain-middleware/pkg/db/mixin"
     8  	crudermixin "github.com/NpoolPlatform/libent-cruder/pkg/mixin"
     9  	basetypes "github.com/NpoolPlatform/message/npool/basetypes/v1"
    10  	"github.com/google/uuid"
    11  	"github.com/shopspring/decimal"
    12  )
    13  
    14  // Tran holds the schema definition for the Tran entity.
    15  type Tran struct {
    16  	ent.Schema
    17  }
    18  
    19  func (Tran) Mixin() []ent.Mixin {
    20  	return []ent.Mixin{
    21  		mixin.TimeMixin{},
    22  		crudermixin.AutoIDMixin{},
    23  	}
    24  }
    25  
    26  // Fields of the Tran.
    27  func (Tran) Fields() []ent.Field {
    28  	return []ent.Field{
    29  		field.
    30  			UUID("coin_type_id", uuid.UUID{}).
    31  			Optional().
    32  			Default(func() uuid.UUID {
    33  				return uuid.UUID{}
    34  			}),
    35  		field.
    36  			UUID("from_account_id", uuid.UUID{}).
    37  			Optional().
    38  			Default(func() uuid.UUID {
    39  				return uuid.UUID{}
    40  			}),
    41  		field.
    42  			UUID("to_account_id", uuid.UUID{}).
    43  			Optional().
    44  			Default(func() uuid.UUID {
    45  				return uuid.UUID{}
    46  			}),
    47  		field.
    48  			Other("amount", decimal.Decimal{}).
    49  			SchemaType(map[string]string{
    50  				dialect.MySQL: "decimal(37,18)",
    51  			}).
    52  			Optional().
    53  			Default(decimal.Decimal{}),
    54  		field.
    55  			Other("fee_amount", decimal.Decimal{}).
    56  			SchemaType(map[string]string{
    57  				dialect.MySQL: "decimal(37,18)",
    58  			}).
    59  			Optional().
    60  			Default(decimal.Decimal{}),
    61  		field.
    62  			String("chain_tx_id").
    63  			Optional().
    64  			Default(""),
    65  		field.
    66  			String("state").
    67  			Optional().
    68  			Default(basetypes.TxState_DefaultTxState.String()),
    69  		field.
    70  			String("extra").
    71  			Optional().
    72  			Default(""),
    73  		field.
    74  			String("type").
    75  			Optional().
    76  			Default(basetypes.TxType_DefaultTxType.String()),
    77  	}
    78  }
    79  
    80  // Edges of the Tran.
    81  func (Tran) Edges() []ent.Edge {
    82  	return nil
    83  }