|
| 1 | +package fevm |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "go.opencensus.io/tag" |
| 7 | + |
| 8 | + "github.com/filecoin-project/lily/metrics" |
| 9 | + "github.com/filecoin-project/lily/model" |
| 10 | +) |
| 11 | + |
| 12 | +type FEVMContract struct { |
| 13 | + tableName struct{} `pg:"fevm_contracts"` // nolint: structcheck |
| 14 | + |
| 15 | + // Height message was executed at. |
| 16 | + Height int64 `pg:",pk,notnull,use_zero"` |
| 17 | + |
| 18 | + // Actor address. |
| 19 | + ActorID string `pg:",notnull"` |
| 20 | + |
| 21 | + // Actor Address in ETH |
| 22 | + EthAddress string `pg:",notnull"` |
| 23 | + |
| 24 | + ByteCode string `pg:",notnull"` |
| 25 | + ByteCodeHash string `pg:",notnull"` |
| 26 | + |
| 27 | + Balance string `pg:"type:numeric,notnull"` |
| 28 | + Nonce uint64 `pg:",use_zero"` |
| 29 | +} |
| 30 | + |
| 31 | +func (f *FEVMContract) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { |
| 32 | + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_contracts")) |
| 33 | + metrics.RecordCount(ctx, metrics.PersistModel, 1) |
| 34 | + return s.PersistModel(ctx, f) |
| 35 | +} |
| 36 | + |
| 37 | +type FEVMContractList []*FEVMContract |
| 38 | + |
| 39 | +func (f FEVMContractList) Persist(ctx context.Context, s model.StorageBatch, version model.Version) error { |
| 40 | + if len(f) == 0 { |
| 41 | + return nil |
| 42 | + } |
| 43 | + ctx, _ = tag.New(ctx, tag.Upsert(metrics.Table, "fevm_contracts")) |
| 44 | + metrics.RecordCount(ctx, metrics.PersistModel, len(f)) |
| 45 | + return s.PersistModel(ctx, f) |
| 46 | +} |
0 commit comments