github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/monitor/pos.go (about) 1 package monitor 2 3 import ( 4 "context" 5 6 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/middleware" 7 "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx" 8 "github.com/machinefi/w3bstream/pkg/modules/blockchain" 9 "github.com/machinefi/w3bstream/pkg/types" 10 ) 11 12 type CreateContractLog struct { 13 httpx.MethodPost 14 blockchain.CreateContractLogReq `in:"body"` 15 } 16 17 func (r *CreateContractLog) Path() string { return "/contract_log" } 18 19 func (r *CreateContractLog) Output(ctx context.Context) (interface{}, error) { 20 ctx, err := middleware.MustCurrentAccountFromContext(ctx). 21 WithProjectContextByName(ctx, middleware.MustProjectName(ctx)) 22 if err != nil { 23 return nil, err 24 } 25 26 r.ProjectName = types.MustProjectFromContext(ctx).ProjectName.Name 27 return blockchain.CreateContractLog(ctx, &r.CreateContractLogReq) 28 } 29 30 type CreateChainTx struct { 31 httpx.MethodPost 32 blockchain.CreateChainTxReq `in:"body"` 33 } 34 35 func (r *CreateChainTx) Path() string { return "/chain_tx" } 36 37 func (r *CreateChainTx) Output(ctx context.Context) (interface{}, error) { 38 ctx, err := middleware.MustCurrentAccountFromContext(ctx). 39 WithProjectContextByName(ctx, middleware.MustProjectName(ctx)) 40 if err != nil { 41 return nil, err 42 } 43 44 r.ProjectName = types.MustProjectFromContext(ctx).ProjectName.Name 45 return blockchain.CreateChainTx(ctx, &r.CreateChainTxReq) 46 } 47 48 type CreateChainHeight struct { 49 httpx.MethodPost 50 blockchain.CreateChainHeightReq `in:"body"` 51 } 52 53 func (r *CreateChainHeight) Path() string { return "/chain_height" } 54 55 func (r *CreateChainHeight) Output(ctx context.Context) (interface{}, error) { 56 ctx, err := middleware.MustCurrentAccountFromContext(ctx). 57 WithProjectContextByName(ctx, middleware.MustProjectName(ctx)) 58 if err != nil { 59 return nil, err 60 } 61 62 r.ProjectName = types.MustProjectFromContext(ctx).ProjectName.Name 63 return blockchain.CreateChainHeight(ctx, &r.CreateChainHeightReq) 64 }