mirror of
https://github.com/alexgo-io/gaze-indexer.git
synced 2026-01-12 08:34:28 +08:00
* feat: recover nodesale module. * fix: refactored. * fix: fix table type. * fix: add entity * fix: bug UTC time. * ci: try to tidy before testing * ci: touch result file * ci: use echo to create new file * fix: try to skip test in ci * fix: remove os.Exit * fix: handle error * feat: add todo note * fix: Cannot run nodesale test because qtx is not initiated. * fix: 50% chance public key compare incorrectly. * fix: more consistent SQL * fix: sanity refactor. * fix: remove unused code. * fix: move last_block_default to config file. * fix: minor mistakes. * fix: * fix: refactor * fix: refactor * fix: delegate tx hash not record into db. * refactor: prepare for moving integration tests. * refactor: convert to unit tests. * fix: change to using input values since output values deducted fee. * feat: add extra unit test. * fix: wrong timestamp format. * fix: handle block timeout = 0 --------- Co-authored-by: Gaze <gazenw@users.noreply.github.com>
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package delegate
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/cockroachdb/errors"
|
|
"github.com/gaze-network/indexer-network/modules/nodesale/datagateway"
|
|
"github.com/gaze-network/indexer-network/modules/nodesale/internal/entity"
|
|
"github.com/gaze-network/indexer-network/modules/nodesale/internal/validator"
|
|
"github.com/gaze-network/indexer-network/modules/nodesale/protobuf"
|
|
)
|
|
|
|
type DelegateValidator struct {
|
|
validator.Validator
|
|
}
|
|
|
|
func New() *DelegateValidator {
|
|
v := validator.New()
|
|
return &DelegateValidator{
|
|
Validator: *v,
|
|
}
|
|
}
|
|
|
|
func (v *DelegateValidator) NodesExist(
|
|
ctx context.Context,
|
|
qtx datagateway.NodeSaleDataGatewayWithTx,
|
|
deployId *protobuf.ActionID,
|
|
nodeIds []uint32,
|
|
) (bool, []entity.Node, error) {
|
|
if !v.Valid {
|
|
return false, nil, nil
|
|
}
|
|
|
|
nodes, err := qtx.GetNodesByIds(ctx, datagateway.GetNodesByIdsParams{
|
|
SaleBlock: deployId.Block,
|
|
SaleTxIndex: deployId.TxIndex,
|
|
NodeIds: nodeIds,
|
|
})
|
|
if err != nil {
|
|
v.Valid = false
|
|
return v.Valid, nil, errors.Wrap(err, "Failed to get nodes")
|
|
}
|
|
|
|
if len(nodeIds) != len(nodes) {
|
|
v.Valid = false
|
|
return v.Valid, nil, nil
|
|
}
|
|
|
|
v.Valid = true
|
|
return v.Valid, nodes, nil
|
|
}
|