github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/modules/blockchain/api.go (about)

     1  package blockchain
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx"
     7  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder"
     8  	"github.com/machinefi/w3bstream/pkg/errors/status"
     9  	"github.com/machinefi/w3bstream/pkg/models"
    10  	"github.com/machinefi/w3bstream/pkg/types"
    11  )
    12  
    13  const chainUniqFlag = 0
    14  
    15  type BatchUpdateMonitorReq struct {
    16  	IDs []types.SFID `json:"ids"`
    17  }
    18  
    19  func RemoveMonitor(ctx context.Context, projectName string) error {
    20  	d := types.MustMonitorDBExecutorFromContext(ctx)
    21  
    22  	return sqlx.NewTasks(d).With(
    23  		func(d sqlx.DBExecutor) error {
    24  			m := &models.ContractLog{}
    25  
    26  			expr := builder.Delete().From(d.T(m), builder.Where(m.ColProjectName().Eq(projectName)))
    27  			if _, err := d.Exec(expr); err != nil {
    28  				return status.DatabaseError.StatusErr().WithDesc(err.Error())
    29  			}
    30  			return nil
    31  		},
    32  		func(d sqlx.DBExecutor) error {
    33  			m := &models.ChainTx{}
    34  
    35  			expr := builder.Delete().From(d.T(m), builder.Where(m.ColProjectName().Eq(projectName)))
    36  			if _, err := d.Exec(expr); err != nil {
    37  				return status.DatabaseError.StatusErr().WithDesc(err.Error())
    38  			}
    39  			return nil
    40  		},
    41  		func(d sqlx.DBExecutor) error {
    42  			m := &models.ChainHeight{}
    43  
    44  			expr := builder.Delete().From(d.T(m), builder.Where(m.ColProjectName().Eq(projectName)))
    45  			if _, err := d.Exec(expr); err != nil {
    46  				return status.DatabaseError.StatusErr().WithDesc(err.Error())
    47  			}
    48  			return nil
    49  		},
    50  	).Do()
    51  }