diff --git a/utils/util.go b/utils/util.go index 6f19082e..9771212a 100644 --- a/utils/util.go +++ b/utils/util.go @@ -3,6 +3,7 @@ package utils import ( "context" "errors" + "github.com/nervosnetwork/ckb-sdk-go/indexer" "github.com/nervosnetwork/ckb-sdk-go/rpc" "github.com/nervosnetwork/ckb-sdk-go/types" "math/big" @@ -89,7 +90,7 @@ func getCellbaseMaturity(client rpc.Client, ctx context.Context, cellbaseMaturit if err != nil { return nil, err } - major, minor, _, err := ParseNodeVersion(nodeInfo.Version) + major, minor, _, err := parseNodeVersion(nodeInfo.Version) if err != nil { return nil, err } @@ -141,8 +142,7 @@ func isTipEpochLessThanCellbaseMaturity(tipEpochR, cellbaseMaturityR *big.Rat) b return false } -// ParseNodeVersion return ckb node version number -func ParseNodeVersion(nodeVersion string) (int, int, int, error) { +func parseNodeVersion(nodeVersion string) (int, int, int, error) { reg, err := regexp.Compile("\\d+(\\.\\d+){0,2}") if err != nil { return 0, 0, 0, err @@ -164,3 +164,8 @@ func ParseNodeVersion(nodeVersion string) (int, int, int, error) { } return major, minor, patch, nil } + +// IsMature check if a cellbase live cell is mature +func IsMature(cell *indexer.LiveCell, maxMatureBlockNumber uint64) bool { + return cell.TxIndex > 0 || cell.BlockNumber == 0 || cell.BlockNumber <= maxMatureBlockNumber +} diff --git a/utils/util_test.go b/utils/util_test.go index 861abef6..773dc809 100644 --- a/utils/util_test.go +++ b/utils/util_test.go @@ -122,7 +122,7 @@ func Test_calcMaxMatureBlockNumber(t *testing.T) { } } -func TestParseNodeVersion(t *testing.T) { +func Test_parseNodeVersion(t *testing.T) { type args struct { nodeVersion string } @@ -161,19 +161,19 @@ func TestParseNodeVersion(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, got1, got2, err := ParseNodeVersion(tt.args.nodeVersion) + got, got1, got2, err := parseNodeVersion(tt.args.nodeVersion) if (err != nil) != tt.wantErr { - t.Errorf("ParseNodeVersion() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("parseNodeVersion() error = %v, wantErr %v", err, tt.wantErr) return } if got != tt.want { - t.Errorf("ParseNodeVersion() got = %v, want %v", got, tt.want) + t.Errorf("parseNodeVersion() got = %v, want %v", got, tt.want) } if got1 != tt.want1 { - t.Errorf("ParseNodeVersion() got1 = %v, want %v", got1, tt.want1) + t.Errorf("parseNodeVersion() got1 = %v, want %v", got1, tt.want1) } if got2 != tt.want2 { - t.Errorf("ParseNodeVersion() got2 = %v, want %v", got2, tt.want2) + t.Errorf("parseNodeVersion() got2 = %v, want %v", got2, tt.want2) } }) }