From 59be6278362613e46555ed50b09c18a3a93045ea Mon Sep 17 00:00:00 2001 From: HoangPham Date: Fri, 29 Apr 2022 11:21:46 +0700 Subject: [PATCH 1/6] Update query contract --- graph/generated/generated.go | 1710 ++++++++++++++++++++++++++++++++-- graph/model/models_gen.go | 29 + graph/schema.graphqls | 44 + graph/schema.resolvers.go | 24 + orm/document/code.go | 75 ++ orm/document/contract.go | 78 ++ 6 files changed, 1894 insertions(+), 66 deletions(-) create mode 100644 orm/document/code.go create mode 100644 orm/document/contract.go diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 7fccbf8..3ef4b80 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -78,6 +78,19 @@ type ComplexityRoot struct { Value func(childComplexity int) int } + Code struct { + CodeID func(childComplexity int) int + Contract func(childComplexity int) int + CreatedAt func(childComplexity int) int + Creator func(childComplexity int) int + DataHash func(childComplexity int) int + InstantiateCount func(childComplexity int) int + Permission func(childComplexity int) int + PermittedAddress func(childComplexity int) int + Txhash func(childComplexity int) int + Version func(childComplexity int) int + } + Commission struct { Commission func(childComplexity int) int } @@ -100,6 +113,22 @@ type ComplexityRoot struct { Type func(childComplexity int) int } + Contract struct { + Admin func(childComplexity int) int + CodeID func(childComplexity int) int + Contract func(childComplexity int) int + ContractAddress func(childComplexity int) int + Creator func(childComplexity int) int + ExecutedCount func(childComplexity int) int + InstantiatedAt func(childComplexity int) int + Label func(childComplexity int) int + LastExecutedAt func(childComplexity int) int + Permission func(childComplexity int) int + PermittedAddress func(childComplexity int) int + Txhash func(childComplexity int) int + Version func(childComplexity int) int + } + Delegation struct { Amount func(childComplexity int) int DelegatorAddress func(childComplexity int) int @@ -185,7 +214,10 @@ type ComplexityRoot struct { BlockDetail func(childComplexity int, height *int) int BlockTxs func(childComplexity int, height *int) int Blocks func(childComplexity int, offset *int, size *int) int + CodeDetail func(childComplexity int, codeID int) int + Codes func(childComplexity int, after int, size int) int Commission func(childComplexity int, operatorAddress string) int + Contracts func(childComplexity int, offset int, size int, keyword *string) int Delegations func(childComplexity int, accAddress string) int Delegators func(childComplexity int, operatorAddress string, offset int) int Deposit func(childComplexity int, proposalID int) int @@ -369,6 +401,9 @@ type QueryResolver interface { Price(ctx context.Context, slug string) (*model.Price, error) StatsAssets(ctx context.Context) ([]*model.StatsAsset, error) Delegators(ctx context.Context, operatorAddress string, offset int) (*model.DelegatorResponse, error) + Codes(ctx context.Context, after int, size int) ([]*model.Code, error) + CodeDetail(ctx context.Context, codeID int) (*model.Code, error) + Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) } type executableSchema struct { @@ -512,6 +547,76 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Change.Value(childComplexity), true + case "Code.code_id": + if e.complexity.Code.CodeID == nil { + break + } + + return e.complexity.Code.CodeID(childComplexity), true + + case "Code.contract": + if e.complexity.Code.Contract == nil { + break + } + + return e.complexity.Code.Contract(childComplexity), true + + case "Code.created_at": + if e.complexity.Code.CreatedAt == nil { + break + } + + return e.complexity.Code.CreatedAt(childComplexity), true + + case "Code.creator": + if e.complexity.Code.Creator == nil { + break + } + + return e.complexity.Code.Creator(childComplexity), true + + case "Code.data_hash": + if e.complexity.Code.DataHash == nil { + break + } + + return e.complexity.Code.DataHash(childComplexity), true + + case "Code.instantiate_count": + if e.complexity.Code.InstantiateCount == nil { + break + } + + return e.complexity.Code.InstantiateCount(childComplexity), true + + case "Code.permission": + if e.complexity.Code.Permission == nil { + break + } + + return e.complexity.Code.Permission(childComplexity), true + + case "Code.permitted_address": + if e.complexity.Code.PermittedAddress == nil { + break + } + + return e.complexity.Code.PermittedAddress(childComplexity), true + + case "Code.txhash": + if e.complexity.Code.Txhash == nil { + break + } + + return e.complexity.Code.Txhash(childComplexity), true + + case "Code.version": + if e.complexity.Code.Version == nil { + break + } + + return e.complexity.Code.Version(childComplexity), true + case "Commission.commission": if e.complexity.Commission.Commission == nil { break @@ -582,6 +687,97 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Content.Type(childComplexity), true + case "Contract.admin": + if e.complexity.Contract.Admin == nil { + break + } + + return e.complexity.Contract.Admin(childComplexity), true + + case "Contract.code_id": + if e.complexity.Contract.CodeID == nil { + break + } + + return e.complexity.Contract.CodeID(childComplexity), true + + case "Contract.contract": + if e.complexity.Contract.Contract == nil { + break + } + + return e.complexity.Contract.Contract(childComplexity), true + + case "Contract.contract_address": + if e.complexity.Contract.ContractAddress == nil { + break + } + + return e.complexity.Contract.ContractAddress(childComplexity), true + + case "Contract.creator": + if e.complexity.Contract.Creator == nil { + break + } + + return e.complexity.Contract.Creator(childComplexity), true + + case "Contract.executed_count": + if e.complexity.Contract.ExecutedCount == nil { + break + } + + return e.complexity.Contract.ExecutedCount(childComplexity), true + + case "Contract.instantiated_at": + if e.complexity.Contract.InstantiatedAt == nil { + break + } + + return e.complexity.Contract.InstantiatedAt(childComplexity), true + + case "Contract.label": + if e.complexity.Contract.Label == nil { + break + } + + return e.complexity.Contract.Label(childComplexity), true + + case "Contract.last_executed_at": + if e.complexity.Contract.LastExecutedAt == nil { + break + } + + return e.complexity.Contract.LastExecutedAt(childComplexity), true + + case "Contract.permission": + if e.complexity.Contract.Permission == nil { + break + } + + return e.complexity.Contract.Permission(childComplexity), true + + case "Contract.permitted_address": + if e.complexity.Contract.PermittedAddress == nil { + break + } + + return e.complexity.Contract.PermittedAddress(childComplexity), true + + case "Contract.txhash": + if e.complexity.Contract.Txhash == nil { + break + } + + return e.complexity.Contract.Txhash(childComplexity), true + + case "Contract.version": + if e.complexity.Contract.Version == nil { + break + } + + return e.complexity.Contract.Version(childComplexity), true + case "Delegation.amount": if e.complexity.Delegation.Amount == nil { break @@ -969,6 +1165,30 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Blocks(childComplexity, args["offset"].(*int), args["size"].(*int)), true + case "Query.code_detail": + if e.complexity.Query.CodeDetail == nil { + break + } + + args, err := ec.field_Query_code_detail_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.CodeDetail(childComplexity, args["code_id"].(int)), true + + case "Query.codes": + if e.complexity.Query.Codes == nil { + break + } + + args, err := ec.field_Query_codes_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Codes(childComplexity, args["after"].(int), args["size"].(int)), true + case "Query.commission": if e.complexity.Query.Commission == nil { break @@ -981,6 +1201,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Commission(childComplexity, args["operator_address"].(string)), true + case "Query.contracts": + if e.complexity.Query.Contracts == nil { + break + } + + args, err := ec.field_Query_contracts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.Contracts(childComplexity, args["offset"].(int), args["size"].(int), args["keyword"].(*string)), true + case "Query.delegations": if e.complexity.Query.Delegations == nil { break @@ -2036,6 +2268,35 @@ type DelegatorResponse { total_count: Int! } +type Code { + code_id: Int! + contract: String! + data_hash: String! + created_at: String! + creator: String! + instantiate_count: Int! + permission: String! + permitted_address: String! + txhash: String! + version: String! +} + +type Contract { + code_id: Int! + contract: String! + contract_address: String! + admin: String! + creator: String! + executed_count: Int! + instantiated_at: String! + label: String! + last_executed_at: String! + permission: String! + permitted_address: String! + txhash: String! + version: String! +} + type Query { blocks(offset: Int, size: Int): [Block!]! block_detail(height: Int): Block! @@ -2108,6 +2369,21 @@ type Query { Get delegators in validator detail """ delegators(operator_address: String!, offset: Int!): DelegatorResponse! + + """ + Get list code + """ + codes(after: Int!, size: Int!): [Code!]! + + """ + Get code detail + """ + code_detail(code_id: Int!): Code! + + """ + Get list contract + """ + contracts(offset: Int!, size: Int!, keyword: String): [Contract!]! } `, BuiltIn: false}, } @@ -2249,6 +2525,45 @@ func (ec *executionContext) field_Query_blocks_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Query_code_detail_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["code_id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("code_id")) + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["code_id"] = arg0 + return args, nil +} + +func (ec *executionContext) field_Query_codes_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["after"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("after")) + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["after"] = arg0 + var arg1 int + if tmp, ok := rawArgs["size"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("size")) + arg1, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["size"] = arg1 + return args, nil +} + func (ec *executionContext) field_Query_commission_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -2264,6 +2579,39 @@ func (ec *executionContext) field_Query_commission_args(ctx context.Context, raw return args, nil } +func (ec *executionContext) field_Query_contracts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["offset"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("offset")) + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["offset"] = arg0 + var arg1 int + if tmp, ok := rawArgs["size"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("size")) + arg1, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["size"] = arg1 + var arg2 *string + if tmp, ok := rawArgs["keyword"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("keyword")) + arg2, err = ec.unmarshalOString2ᚖstring(ctx, tmp) + if err != nil { + return nil, err + } + } + args["keyword"] = arg2 + return args, nil +} + func (ec *executionContext) field_Query_delegations_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -3220,7 +3568,7 @@ func (ec *executionContext) _Change_subspace(ctx context.Context, field graphql. return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Commission_commission(ctx context.Context, field graphql.CollectedField, obj *model.Commission) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_code_id(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3228,7 +3576,7 @@ func (ec *executionContext) _Commission_commission(ctx context.Context, field gr } }() fc := &graphql.FieldContext{ - Object: "Commission", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3238,21 +3586,24 @@ func (ec *executionContext) _Commission_commission(ctx context.Context, field gr ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Commission, nil + return obj.CodeID, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } return graphql.Null } - res := resTmp.(*model.Commissions) + res := resTmp.(int) fc.Result = res - return ec.marshalOCommissions2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCommissions(ctx, field.Selections, res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _CommissionInfo_denom(ctx context.Context, field graphql.CollectedField, obj *model.CommissionInfo) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_contract(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3260,7 +3611,7 @@ func (ec *executionContext) _CommissionInfo_denom(ctx context.Context, field gra } }() fc := &graphql.FieldContext{ - Object: "CommissionInfo", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3270,7 +3621,7 @@ func (ec *executionContext) _CommissionInfo_denom(ctx context.Context, field gra ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Denom, nil + return obj.Contract, nil }) if err != nil { ec.Error(ctx, err) @@ -3287,7 +3638,7 @@ func (ec *executionContext) _CommissionInfo_denom(ctx context.Context, field gra return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _CommissionInfo_amount(ctx context.Context, field graphql.CollectedField, obj *model.CommissionInfo) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_data_hash(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3295,7 +3646,7 @@ func (ec *executionContext) _CommissionInfo_amount(ctx context.Context, field gr } }() fc := &graphql.FieldContext{ - Object: "CommissionInfo", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3305,7 +3656,7 @@ func (ec *executionContext) _CommissionInfo_amount(ctx context.Context, field gr ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Amount, nil + return obj.DataHash, nil }) if err != nil { ec.Error(ctx, err) @@ -3322,7 +3673,7 @@ func (ec *executionContext) _CommissionInfo_amount(ctx context.Context, field gr return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Commissions_commission(ctx context.Context, field graphql.CollectedField, obj *model.Commissions) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_created_at(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3330,7 +3681,7 @@ func (ec *executionContext) _Commissions_commission(ctx context.Context, field g } }() fc := &graphql.FieldContext{ - Object: "Commissions", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3340,7 +3691,7 @@ func (ec *executionContext) _Commissions_commission(ctx context.Context, field g ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Commission, nil + return obj.CreatedAt, nil }) if err != nil { ec.Error(ctx, err) @@ -3352,12 +3703,12 @@ func (ec *executionContext) _Commissions_commission(ctx context.Context, field g } return graphql.Null } - res := resTmp.([]*model.CommissionInfo) + res := resTmp.(string) fc.Result = res - return ec.marshalNCommissionInfo2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCommissionInfoᚄ(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Content_title(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_creator(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3365,7 +3716,7 @@ func (ec *executionContext) _Content_title(ctx context.Context, field graphql.Co } }() fc := &graphql.FieldContext{ - Object: "Content", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3375,7 +3726,7 @@ func (ec *executionContext) _Content_title(ctx context.Context, field graphql.Co ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Title, nil + return obj.Creator, nil }) if err != nil { ec.Error(ctx, err) @@ -3392,7 +3743,7 @@ func (ec *executionContext) _Content_title(ctx context.Context, field graphql.Co return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Content_type(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_instantiate_count(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3400,7 +3751,7 @@ func (ec *executionContext) _Content_type(ctx context.Context, field graphql.Col } }() fc := &graphql.FieldContext{ - Object: "Content", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3410,7 +3761,7 @@ func (ec *executionContext) _Content_type(ctx context.Context, field graphql.Col ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Type, nil + return obj.InstantiateCount, nil }) if err != nil { ec.Error(ctx, err) @@ -3422,12 +3773,12 @@ func (ec *executionContext) _Content_type(ctx context.Context, field graphql.Col } return graphql.Null } - res := resTmp.(string) + res := resTmp.(int) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNInt2int(ctx, field.Selections, res) } -func (ec *executionContext) _Content_description(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_permission(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3435,7 +3786,7 @@ func (ec *executionContext) _Content_description(ctx context.Context, field grap } }() fc := &graphql.FieldContext{ - Object: "Content", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3445,7 +3796,7 @@ func (ec *executionContext) _Content_description(ctx context.Context, field grap ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Description, nil + return obj.Permission, nil }) if err != nil { ec.Error(ctx, err) @@ -3462,7 +3813,7 @@ func (ec *executionContext) _Content_description(ctx context.Context, field grap return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Content_amount(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_permitted_address(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3470,7 +3821,7 @@ func (ec *executionContext) _Content_amount(ctx context.Context, field graphql.C } }() fc := &graphql.FieldContext{ - Object: "Content", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3480,7 +3831,7 @@ func (ec *executionContext) _Content_amount(ctx context.Context, field graphql.C ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Amount, nil + return obj.PermittedAddress, nil }) if err != nil { ec.Error(ctx, err) @@ -3492,12 +3843,12 @@ func (ec *executionContext) _Content_amount(ctx context.Context, field graphql.C } return graphql.Null } - res := resTmp.([]*model.Amount) + res := resTmp.(string) fc.Result = res - return ec.marshalNAmount2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐAmountᚄ(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Content_changes(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_txhash(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3505,7 +3856,7 @@ func (ec *executionContext) _Content_changes(ctx context.Context, field graphql. } }() fc := &graphql.FieldContext{ - Object: "Content", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3515,7 +3866,7 @@ func (ec *executionContext) _Content_changes(ctx context.Context, field graphql. ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Changes, nil + return obj.Txhash, nil }) if err != nil { ec.Error(ctx, err) @@ -3527,12 +3878,12 @@ func (ec *executionContext) _Content_changes(ctx context.Context, field graphql. } return graphql.Null } - res := resTmp.([]*model.Change) + res := resTmp.(string) fc.Result = res - return ec.marshalNChange2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐChangeᚄ(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Content_plan(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { +func (ec *executionContext) _Code_version(ctx context.Context, field graphql.CollectedField, obj *model.Code) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3540,7 +3891,7 @@ func (ec *executionContext) _Content_plan(ctx context.Context, field graphql.Col } }() fc := &graphql.FieldContext{ - Object: "Content", + Object: "Code", Field: field, Args: nil, IsMethod: false, @@ -3550,7 +3901,7 @@ func (ec *executionContext) _Content_plan(ctx context.Context, field graphql.Col ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Plan, nil + return obj.Version, nil }) if err != nil { ec.Error(ctx, err) @@ -3562,12 +3913,12 @@ func (ec *executionContext) _Content_plan(ctx context.Context, field graphql.Col } return graphql.Null } - res := resTmp.(*model.Plan) + res := resTmp.(string) fc.Result = res - return ec.marshalNPlan2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐPlan(ctx, field.Selections, res) + return ec.marshalNString2string(ctx, field.Selections, res) } -func (ec *executionContext) _Delegation_moniker(ctx context.Context, field graphql.CollectedField, obj *model.Delegation) (ret graphql.Marshaler) { +func (ec *executionContext) _Commission_commission(ctx context.Context, field graphql.CollectedField, obj *model.Commission) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -3575,7 +3926,7 @@ func (ec *executionContext) _Delegation_moniker(ctx context.Context, field graph } }() fc := &graphql.FieldContext{ - Object: "Delegation", + Object: "Commission", Field: field, Args: nil, IsMethod: false, @@ -3585,19 +3936,821 @@ func (ec *executionContext) _Delegation_moniker(ctx context.Context, field graph ctx = graphql.WithFieldContext(ctx, fc) resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.Moniker, nil + return obj.Commission, nil }) if err != nil { ec.Error(ctx, err) return graphql.Null } if resTmp == nil { - if !graphql.HasFieldError(ctx, fc) { - ec.Errorf(ctx, "must not be null") - } return graphql.Null } - res := resTmp.(string) + res := resTmp.(*model.Commissions) + fc.Result = res + return ec.marshalOCommissions2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCommissions(ctx, field.Selections, res) +} + +func (ec *executionContext) _CommissionInfo_denom(ctx context.Context, field graphql.CollectedField, obj *model.CommissionInfo) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "CommissionInfo", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Denom, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _CommissionInfo_amount(ctx context.Context, field graphql.CollectedField, obj *model.CommissionInfo) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "CommissionInfo", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Amount, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Commissions_commission(ctx context.Context, field graphql.CollectedField, obj *model.Commissions) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Commissions", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Commission, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.CommissionInfo) + fc.Result = res + return ec.marshalNCommissionInfo2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCommissionInfoᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) _Content_title(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Content", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Title, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Content_type(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Content", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Type, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Content_description(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Content", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Description, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Content_amount(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Content", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Amount, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Amount) + fc.Result = res + return ec.marshalNAmount2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐAmountᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) _Content_changes(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Content", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Changes, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Change) + fc.Result = res + return ec.marshalNChange2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐChangeᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) _Content_plan(ctx context.Context, field graphql.CollectedField, obj *model.Content) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Content", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Plan, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Plan) + fc.Result = res + return ec.marshalNPlan2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐPlan(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_code_id(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.CodeID, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_contract(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Contract, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_contract_address(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ContractAddress, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_admin(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Admin, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_creator(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Creator, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_executed_count(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.ExecutedCount, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(int) + fc.Result = res + return ec.marshalNInt2int(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_instantiated_at(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.InstantiatedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_label(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Label, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_last_executed_at(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.LastExecutedAt, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_permission(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Permission, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_permitted_address(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.PermittedAddress, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_txhash(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Txhash, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Contract_version(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Version, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Delegation_moniker(ctx context.Context, field graphql.CollectedField, obj *model.Delegation) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Delegation", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Moniker, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) fc.Result = res return ec.marshalNString2string(ctx, field.Selections, res) } @@ -6090,7 +7243,126 @@ func (ec *executionContext) _Query_vote(ctx context.Context, field graphql.Colle fc.Args = args resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Vote(rctx, args["before"].(*int), args["size"].(*int), args["proposal_id"].(int)) + return ec.resolvers.Query().Vote(rctx, args["before"].(*int), args["size"].(*int), args["proposal_id"].(int)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Vote) + fc.Result = res + return ec.marshalNVote2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐVoteᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_price(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_price_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Price(rctx, args["slug"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Price) + fc.Result = res + return ec.marshalNPrice2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐPrice(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_stats_assets(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().StatsAssets(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.StatsAsset) + fc.Result = res + return ec.marshalNStatsAsset2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐStatsAssetᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) _Query_delegators(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_delegators_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Delegators(rctx, args["operator_address"].(string), args["offset"].(int)) }) if err != nil { ec.Error(ctx, err) @@ -6102,12 +7374,12 @@ func (ec *executionContext) _Query_vote(ctx context.Context, field graphql.Colle } return graphql.Null } - res := resTmp.([]*model.Vote) + res := resTmp.(*model.DelegatorResponse) fc.Result = res - return ec.marshalNVote2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐVoteᚄ(ctx, field.Selections, res) + return ec.marshalNDelegatorResponse2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐDelegatorResponse(ctx, field.Selections, res) } -func (ec *executionContext) _Query_price(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { +func (ec *executionContext) _Query_codes(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -6124,7 +7396,7 @@ func (ec *executionContext) _Query_price(ctx context.Context, field graphql.Coll ctx = graphql.WithFieldContext(ctx, fc) rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Query_price_args(ctx, rawArgs) + args, err := ec.field_Query_codes_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null @@ -6132,7 +7404,7 @@ func (ec *executionContext) _Query_price(ctx context.Context, field graphql.Coll fc.Args = args resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Price(rctx, args["slug"].(string)) + return ec.resolvers.Query().Codes(rctx, args["after"].(int), args["size"].(int)) }) if err != nil { ec.Error(ctx, err) @@ -6144,12 +7416,12 @@ func (ec *executionContext) _Query_price(ctx context.Context, field graphql.Coll } return graphql.Null } - res := resTmp.(*model.Price) + res := resTmp.([]*model.Code) fc.Result = res - return ec.marshalNPrice2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐPrice(ctx, field.Selections, res) + return ec.marshalNCode2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCodeᚄ(ctx, field.Selections, res) } -func (ec *executionContext) _Query_stats_assets(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { +func (ec *executionContext) _Query_code_detail(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -6165,9 +7437,16 @@ func (ec *executionContext) _Query_stats_assets(ctx context.Context, field graph } ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_code_detail_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().StatsAssets(rctx) + return ec.resolvers.Query().CodeDetail(rctx, args["code_id"].(int)) }) if err != nil { ec.Error(ctx, err) @@ -6179,12 +7458,12 @@ func (ec *executionContext) _Query_stats_assets(ctx context.Context, field graph } return graphql.Null } - res := resTmp.([]*model.StatsAsset) + res := resTmp.(*model.Code) fc.Result = res - return ec.marshalNStatsAsset2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐStatsAssetᚄ(ctx, field.Selections, res) + return ec.marshalNCode2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCode(ctx, field.Selections, res) } -func (ec *executionContext) _Query_delegators(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { +func (ec *executionContext) _Query_contracts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { ec.Error(ctx, ec.Recover(ctx, r)) @@ -6201,7 +7480,7 @@ func (ec *executionContext) _Query_delegators(ctx context.Context, field graphql ctx = graphql.WithFieldContext(ctx, fc) rawArgs := field.ArgumentMap(ec.Variables) - args, err := ec.field_Query_delegators_args(ctx, rawArgs) + args, err := ec.field_Query_contracts_args(ctx, rawArgs) if err != nil { ec.Error(ctx, err) return graphql.Null @@ -6209,7 +7488,7 @@ func (ec *executionContext) _Query_delegators(ctx context.Context, field graphql fc.Args = args resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().Delegators(rctx, args["operator_address"].(string), args["offset"].(int)) + return ec.resolvers.Query().Contracts(rctx, args["offset"].(int), args["size"].(int), args["keyword"].(*string)) }) if err != nil { ec.Error(ctx, err) @@ -6221,9 +7500,9 @@ func (ec *executionContext) _Query_delegators(ctx context.Context, field graphql } return graphql.Null } - res := resTmp.(*model.DelegatorResponse) + res := resTmp.([]*model.Contract) fc.Result = res - return ec.marshalNDelegatorResponse2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐDelegatorResponse(ctx, field.Selections, res) + return ec.marshalNContract2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContractᚄ(ctx, field.Selections, res) } func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { @@ -10230,6 +11509,78 @@ func (ec *executionContext) _Change(ctx context.Context, sel ast.SelectionSet, o return out } +var codeImplementors = []string{"Code"} + +func (ec *executionContext) _Code(ctx context.Context, sel ast.SelectionSet, obj *model.Code) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, codeImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Code") + case "code_id": + out.Values[i] = ec._Code_code_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "contract": + out.Values[i] = ec._Code_contract(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "data_hash": + out.Values[i] = ec._Code_data_hash(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "created_at": + out.Values[i] = ec._Code_created_at(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "creator": + out.Values[i] = ec._Code_creator(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "instantiate_count": + out.Values[i] = ec._Code_instantiate_count(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "permission": + out.Values[i] = ec._Code_permission(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "permitted_address": + out.Values[i] = ec._Code_permitted_address(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "txhash": + out.Values[i] = ec._Code_txhash(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "version": + out.Values[i] = ec._Code_version(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + var commissionImplementors = []string{"Commission"} func (ec *executionContext) _Commission(ctx context.Context, sel ast.SelectionSet, obj *model.Commission) graphql.Marshaler { @@ -10365,6 +11716,93 @@ func (ec *executionContext) _Content(ctx context.Context, sel ast.SelectionSet, return out } +var contractImplementors = []string{"Contract"} + +func (ec *executionContext) _Contract(ctx context.Context, sel ast.SelectionSet, obj *model.Contract) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, contractImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Contract") + case "code_id": + out.Values[i] = ec._Contract_code_id(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "contract": + out.Values[i] = ec._Contract_contract(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "contract_address": + out.Values[i] = ec._Contract_contract_address(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "admin": + out.Values[i] = ec._Contract_admin(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "creator": + out.Values[i] = ec._Contract_creator(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "executed_count": + out.Values[i] = ec._Contract_executed_count(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "instantiated_at": + out.Values[i] = ec._Contract_instantiated_at(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "label": + out.Values[i] = ec._Contract_label(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "last_executed_at": + out.Values[i] = ec._Contract_last_executed_at(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "permission": + out.Values[i] = ec._Contract_permission(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "permitted_address": + out.Values[i] = ec._Contract_permitted_address(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "txhash": + out.Values[i] = ec._Contract_txhash(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "version": + out.Values[i] = ec._Contract_version(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + var delegationImplementors = []string{"Delegation"} func (ec *executionContext) _Delegation(ctx context.Context, sel ast.SelectionSet, obj *model.Delegation) graphql.Marshaler { @@ -11210,6 +12648,48 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } return res }) + case "codes": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_codes(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + case "code_detail": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_code_detail(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) + case "contracts": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_contracts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) case "__type": out.Values[i] = ec._Query___type(ctx, field) case "__schema": @@ -12489,6 +13969,57 @@ func (ec *executionContext) marshalNChange2ᚖgithubᚗcomᚋcosmosᚑgaminghub return ec._Change(ctx, sel, v) } +func (ec *executionContext) marshalNCode2githubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCode(ctx context.Context, sel ast.SelectionSet, v model.Code) graphql.Marshaler { + return ec._Code(ctx, sel, &v) +} + +func (ec *executionContext) marshalNCode2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCodeᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Code) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNCode2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCode(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalNCode2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCode(ctx context.Context, sel ast.SelectionSet, v *model.Code) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Code(ctx, sel, v) +} + func (ec *executionContext) marshalNCommission2githubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCommission(ctx context.Context, sel ast.SelectionSet, v model.Commission) graphql.Marshaler { return ec._Commission(ctx, sel, &v) } @@ -12560,6 +14091,53 @@ func (ec *executionContext) marshalNContent2ᚖgithubᚗcomᚋcosmosᚑgaminghub return ec._Content(ctx, sel, v) } +func (ec *executionContext) marshalNContract2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContractᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Contract) graphql.Marshaler { + ret := make(graphql.Array, len(v)) + var wg sync.WaitGroup + isLen1 := len(v) == 1 + if !isLen1 { + wg.Add(len(v)) + } + for i := range v { + i := i + fc := &graphql.FieldContext{ + Index: &i, + Result: &v[i], + } + ctx := graphql.WithFieldContext(ctx, fc) + f := func(i int) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = nil + } + }() + if !isLen1 { + defer wg.Done() + } + ret[i] = ec.marshalNContract2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContract(ctx, sel, v[i]) + } + if isLen1 { + f(i) + } else { + go f(i) + } + + } + wg.Wait() + return ret +} + +func (ec *executionContext) marshalNContract2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContract(ctx context.Context, sel ast.SelectionSet, v *model.Contract) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Contract(ctx, sel, v) +} + func (ec *executionContext) marshalNDelegation2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐDelegationᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Delegation) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 8a457d8..7d2cd36 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -38,6 +38,19 @@ type Change struct { Subspace string `json:"subspace"` } +type Code struct { + CodeID int `json:"code_id"` + Contract string `json:"contract"` + DataHash string `json:"data_hash"` + CreatedAt string `json:"created_at"` + Creator string `json:"creator"` + InstantiateCount int `json:"instantiate_count"` + Permission string `json:"permission"` + PermittedAddress string `json:"permitted_address"` + Txhash string `json:"txhash"` + Version string `json:"version"` +} + type Commission struct { Commission *Commissions `json:"commission"` } @@ -60,6 +73,22 @@ type Content struct { Plan *Plan `json:"plan"` } +type Contract struct { + CodeID int `json:"code_id"` + Contract string `json:"contract"` + ContractAddress string `json:"contract_address"` + Admin string `json:"admin"` + Creator string `json:"creator"` + ExecutedCount int `json:"executed_count"` + InstantiatedAt string `json:"instantiated_at"` + Label string `json:"label"` + LastExecutedAt string `json:"last_executed_at"` + Permission string `json:"permission"` + PermittedAddress string `json:"permitted_address"` + Txhash string `json:"txhash"` + Version string `json:"version"` +} + type Delegation struct { Moniker string `json:"moniker"` DelegatorAddress string `json:"delegator_address"` diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 810b4db..aa1a969 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -263,6 +263,35 @@ type DelegatorResponse { total_count: Int! } +type Code { + code_id: Int! + contract: String! + data_hash: String! + created_at: String! + creator: String! + instantiate_count: Int! + permission: String! + permitted_address: String! + txhash: String! + version: String! +} + +type Contract { + code_id: Int! + contract: String! + contract_address: String! + admin: String! + creator: String! + executed_count: Int! + instantiated_at: String! + label: String! + last_executed_at: String! + permission: String! + permitted_address: String! + txhash: String! + version: String! +} + type Query { blocks(offset: Int, size: Int): [Block!]! block_detail(height: Int): Block! @@ -335,4 +364,19 @@ type Query { Get delegators in validator detail """ delegators(operator_address: String!, offset: Int!): DelegatorResponse! + + """ + Get list code + """ + codes(after: Int!, size: Int!): [Code!]! + + """ + Get code detail + """ + code_detail(code_id: Int!): Code! + + """ + Get list contract + """ + contracts(offset: Int!, size: Int!, keyword: String): [Contract!]! } diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 3f36b8a..303bc54 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -442,6 +442,30 @@ func (r *queryResolver) Delegators(ctx context.Context, operatorAddress string, }, nil } +func (r *queryResolver) Codes(ctx context.Context, after int, size int) ([]*model.Code, error) { + result, err := document.Code{}.GetCodeListByOffsetAndSize(after, size) + if err != nil { + return []*model.Code{}, nil + } + return document.Code{}.FormatForModel(result) +} + +func (r *queryResolver) CodeDetail(ctx context.Context, codeID int) (*model.Code, error) { + code, err := document.Code{}.FindByCodeId(codeID) + if err != nil { + return &model.Code{}, nil + } + return document.Code{}.FormatModelCodeItem(code), nil +} + +func (r *queryResolver) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) { + result, err := document.Contract{}.GetContractByLimitAndOffset(offset, size, keyword) + if err != nil { + return []*model.Contract{}, nil + } + return document.Contract{}.FormatForModel(result) +} + // Query returns generated.QueryResolver implementation. func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } diff --git a/orm/document/code.go b/orm/document/code.go new file mode 100644 index 0000000..2f88f35 --- /dev/null +++ b/orm/document/code.go @@ -0,0 +1,75 @@ +package document + +import ( + "time" + + "github.com/cosmos-gaminghub/exploder-graphql/graph/model" + "gopkg.in/mgo.v2/bson" +) + +const ( + CollectionCode = "codes" + + CodeIdField = "code_id" +) + +type Code struct { + CodeId int `bson:"code_id"` + Contract string `bson:"contract"` + DataHash string `bson:"data_hash"` + CreatedAt time.Time `bson:"created_at"` + Creator string `bson:"creator"` + InstantiateCount int `bson:"instantiate_count"` + Permission string `bson:"permission"` + PermittedAddress string `bson:"permitted_address"` + TxHash string `bson:"txhash"` + Version string `bson:"version"` +} + +func (_ Code) FindByCodeId(codeId int) (Code, error) { + var code Code + condition := bson.M{ + CodeIdField: codeId, + } + + err := queryOne(CollectionCode, nil, condition, &code) + return code, err +} + +func (_ Code) GetCodeListByOffsetAndSize(before int, size int) ([]Code, error) { + var data []Code + + query := bson.M{} + if before != 0 { + query[CodeIdField] = bson.M{ + "$gt": before, + } + } + + err := querylistByOffsetAndSize(CollectionCode, nil, query, asc(CodeIdField), 0, size, &data) + return data, err +} + +func (_ Code) FormatForModel(results []Code) ([]*model.Code, error) { + var listCode []*model.Code + for _, item := range results { + t := Code{}.FormatModelCodeItem(item) + listCode = append(listCode, t) + } + return listCode, nil +} + +func (_ Code) FormatModelCodeItem(item Code) *model.Code { + return &model.Code{ + CodeID: item.CodeId, + Contract: item.Contract, + DataHash: item.DataHash, + CreatedAt: item.CreatedAt.String(), + Creator: item.Creator, + InstantiateCount: item.InstantiateCount, + Permission: item.Permission, + PermittedAddress: item.PermittedAddress, + Txhash: item.TxHash, + Version: item.Version, + } +} diff --git a/orm/document/contract.go b/orm/document/contract.go new file mode 100644 index 0000000..e30ba68 --- /dev/null +++ b/orm/document/contract.go @@ -0,0 +1,78 @@ +package document + +import ( + "time" + + "github.com/cosmos-gaminghub/exploder-graphql/graph/model" + "gopkg.in/mgo.v2/bson" +) + +const ( + CollectionContract = "contracts" + + ContractAddressField = "contract_address" + ContractLabelField = "label" +) + +type Contract struct { + CodeId int `bson:"code_id"` + Contract string `bson:"contract"` + ContractAddress string `bson:"contract_address"` + Admin string `bson:"admin"` + Creator string `bson:"creator"` + ExecutedCount int `bson:"executed_count"` + InstantiatedAt time.Time `bson:"instantiated_at"` + Label string `bson:"label"` + LastExecutedAt time.Time `bson:"last_executed_at"` + Permission string `bson:"permission"` + PermittedAddress string `bson:"permitted_address"` + TxHash string `bson:"txhash"` + Version string `bson:"version"` +} + +func (d Contract) Name() string { + return CollectionContract +} + +func (_ Contract) FindByContractAddress(contractAddress string) (Contract, error) { + var contract Contract + condition := bson.M{ + ContractAddressField: contractAddress, + } + + err := queryOne(CollectionContract, nil, condition, &contract) + return contract, err +} + +func (_ Contract) GetContractByLimitAndOffset(offset int, size int, keyword *string) ([]Contract, error) { + query := bson.M{} + if keyword != nil { + query[ContractLabelField] = bson.RegEx{ + Pattern: *keyword, + Options: "i", + } + } + + data := []Contract{} + err := querylistByOffsetAndSize(CollectionContract, nil, query, "", offset, size, &data) + return data, err +} + +func (_ Contract) FormatForModel(result []Contract) ([]*model.Contract, error) { + var listContract []*model.Contract + for _, item := range result { + listContract = append(listContract, &model.Contract{ + CodeID: item.CodeId, + ContractAddress: item.ContractAddress, + Label: item.Label, + Contract: item.Contract, + Creator: item.Creator, + ExecutedCount: item.ExecutedCount, + InstantiatedAt: item.InstantiatedAt.String(), + LastExecutedAt: item.LastExecutedAt.String(), + Txhash: item.TxHash, + Version: item.Version, + }) + } + return listContract, nil +} From a6b585553d8dd17649208b227646e720ccc10848 Mon Sep 17 00:00:00 2001 From: HoangPham Date: Tue, 17 May 2022 09:34:26 +0700 Subject: [PATCH 2/6] Update api contract detail --- graph/generated/generated.go | 143 +++++++++++++++++++++++++++++++++++ graph/model/models_gen.go | 1 + graph/schema.graphqls | 6 ++ graph/schema.resolvers.go | 63 ++++++++------- orm/document/contract.go | 120 ++++++++++++++++++++++++----- 5 files changed, 285 insertions(+), 48 deletions(-) diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 3ef4b80..2e8e57c 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -123,6 +123,7 @@ type ComplexityRoot struct { InstantiatedAt func(childComplexity int) int Label func(childComplexity int) int LastExecutedAt func(childComplexity int) int + Messages func(childComplexity int) int Permission func(childComplexity int) int PermittedAddress func(childComplexity int) int Txhash func(childComplexity int) int @@ -217,6 +218,7 @@ type ComplexityRoot struct { CodeDetail func(childComplexity int, codeID int) int Codes func(childComplexity int, after int, size int) int Commission func(childComplexity int, operatorAddress string) int + ContractDetail func(childComplexity int, contractAddress string) int Contracts func(childComplexity int, offset int, size int, keyword *string) int Delegations func(childComplexity int, accAddress string) int Delegators func(childComplexity int, operatorAddress string, offset int) int @@ -404,6 +406,7 @@ type QueryResolver interface { Codes(ctx context.Context, after int, size int) ([]*model.Code, error) CodeDetail(ctx context.Context, codeID int) (*model.Code, error) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) + ContractDetail(ctx context.Context, contractAddress string) (*model.Contract, error) } type executableSchema struct { @@ -750,6 +753,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Contract.LastExecutedAt(childComplexity), true + case "Contract.messages": + if e.complexity.Contract.Messages == nil { + break + } + + return e.complexity.Contract.Messages(childComplexity), true + case "Contract.permission": if e.complexity.Contract.Permission == nil { break @@ -1201,6 +1211,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Commission(childComplexity, args["operator_address"].(string)), true + case "Query.contract_detail": + if e.complexity.Query.ContractDetail == nil { + break + } + + args, err := ec.field_Query_contract_detail_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.ContractDetail(childComplexity, args["contract_address"].(string)), true + case "Query.contracts": if e.complexity.Query.Contracts == nil { break @@ -2295,6 +2317,7 @@ type Contract { permitted_address: String! txhash: String! version: String! + messages: String! } type Query { @@ -2384,6 +2407,11 @@ type Query { Get list contract """ contracts(offset: Int!, size: Int!, keyword: String): [Contract!]! + + """ + Get contract detail + """ + contract_detail(contract_address: String!): Contract! } `, BuiltIn: false}, } @@ -2579,6 +2607,21 @@ func (ec *executionContext) field_Query_commission_args(ctx context.Context, raw return args, nil } +func (ec *executionContext) field_Query_contract_detail_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 string + if tmp, ok := rawArgs["contract_address"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("contract_address")) + arg0, err = ec.unmarshalNString2string(ctx, tmp) + if err != nil { + return nil, err + } + } + args["contract_address"] = arg0 + return args, nil +} + func (ec *executionContext) field_Query_contracts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -4720,6 +4763,41 @@ func (ec *executionContext) _Contract_version(ctx context.Context, field graphql return ec.marshalNString2string(ctx, field.Selections, res) } +func (ec *executionContext) _Contract_messages(ctx context.Context, field graphql.CollectedField, obj *model.Contract) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Contract", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Messages, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _Delegation_moniker(ctx context.Context, field graphql.CollectedField, obj *model.Delegation) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -7505,6 +7583,48 @@ func (ec *executionContext) _Query_contracts(ctx context.Context, field graphql. return ec.marshalNContract2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContractᚄ(ctx, field.Selections, res) } +func (ec *executionContext) _Query_contract_detail(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_contract_detail_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().ContractDetail(rctx, args["contract_address"].(string)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Contract) + fc.Result = res + return ec.marshalNContract2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContract(ctx, field.Selections, res) +} + func (ec *executionContext) _Query___type(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -11792,6 +11912,11 @@ func (ec *executionContext) _Contract(ctx context.Context, sel ast.SelectionSet, if out.Values[i] == graphql.Null { invalids++ } + case "messages": + out.Values[i] = ec._Contract_messages(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -12690,6 +12815,20 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } return res }) + case "contract_detail": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_contract_detail(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) case "__type": out.Values[i] = ec._Query___type(ctx, field) case "__schema": @@ -14091,6 +14230,10 @@ func (ec *executionContext) marshalNContent2ᚖgithubᚗcomᚋcosmosᚑgaminghub return ec._Content(ctx, sel, v) } +func (ec *executionContext) marshalNContract2githubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContract(ctx context.Context, sel ast.SelectionSet, v model.Contract) graphql.Marshaler { + return ec._Contract(ctx, sel, &v) +} + func (ec *executionContext) marshalNContract2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContractᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.Contract) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup diff --git a/graph/model/models_gen.go b/graph/model/models_gen.go index 7d2cd36..fd9a0c7 100644 --- a/graph/model/models_gen.go +++ b/graph/model/models_gen.go @@ -87,6 +87,7 @@ type Contract struct { PermittedAddress string `json:"permitted_address"` Txhash string `json:"txhash"` Version string `json:"version"` + Messages string `json:"messages"` } type Delegation struct { diff --git a/graph/schema.graphqls b/graph/schema.graphqls index aa1a969..02ac5dd 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -290,6 +290,7 @@ type Contract { permitted_address: String! txhash: String! version: String! + messages: String! } type Query { @@ -379,4 +380,9 @@ type Query { Get list contract """ contracts(offset: Int!, size: Int!, keyword: String): [Contract!]! + + """ + Get contract detail + """ + contract_detail(contract_address: String!): Contract! } diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 303bc54..5f41f38 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -18,7 +18,7 @@ import ( func (r *queryResolver) Blocks(ctx context.Context, offset *int, size *int) ([]*model.Block, error) { results, err := document.Block{}.GetBlockListByOffsetAndSize(*offset, *size) if err != nil { - return []*model.Block{}, nil + return []*model.Block{}, err } return document.Block{}.FormatBsonMForModel(results) } @@ -26,7 +26,7 @@ func (r *queryResolver) Blocks(ctx context.Context, offset *int, size *int) ([]* func (r *queryResolver) BlockDetail(ctx context.Context, height *int) (*model.Block, error) { result, err := document.Block{}.QueryBlockByHeight(int64(*height)) if err != nil { - return &model.Block{}, nil + return &model.Block{}, err } return document.Block{}.FormatBsonMForModelBlockDetail(result) } @@ -34,7 +34,7 @@ func (r *queryResolver) BlockDetail(ctx context.Context, height *int) (*model.Bl func (r *queryResolver) BlockTxs(ctx context.Context, height *int) ([]*model.Tx, error) { txs, err := document.CommonTx{}.QueryTxByHeight(int64(*height)) if err != nil { - return []*model.Tx{}, nil + return []*model.Tx{}, err } return document.CommonTx{}.FormatListTxsForModel(txs) } @@ -42,7 +42,7 @@ func (r *queryResolver) BlockTxs(ctx context.Context, height *int) ([]*model.Tx, func (r *queryResolver) Txs(ctx context.Context, size *int) ([]*model.Tx, error) { txs, err := document.CommonTx{}.GetListTxBy(*size) if err != nil { - return []*model.Tx{}, nil + return []*model.Tx{}, err } return document.CommonTx{}.FormatListTxsForModel(txs) } @@ -51,8 +51,7 @@ func (r *queryResolver) TxDetail(ctx context.Context, txHash *string) (*model.Tx tx, err := document.CommonTx{}.QueryTxByHash(*txHash) if err != nil { - fmt.Print(err.Error()) - return &model.Tx{}, nil + return &model.Tx{}, err } return document.CommonTx{}.FormatTxForModel(tx) @@ -61,7 +60,7 @@ func (r *queryResolver) TxDetail(ctx context.Context, txHash *string) (*model.Tx func (r *queryResolver) Validators(ctx context.Context) ([]*model.Validator, error) { validators, err := document.Validator{}.GetValidatorList() if err != nil { - return []*model.Validator{}, nil + return []*model.Validator{}, err } listConsensusAddress := document.Validator{}.GetListConsensusAddress(validators) @@ -98,7 +97,7 @@ func (r *queryResolver) Validators(ctx context.Context) ([]*model.Validator, err func (r *queryResolver) ValidatorDetail(ctx context.Context, operatorAddress *string) (*model.Validator, error) { validator, err := document.Validator{}.QueryValidatorDetailByOperatorAddr(*operatorAddress) if err != nil { - return &model.Validator{}, nil + return &model.Validator{}, err } upTimeCount, overBlocks := document.MissedBlock{}.GetMissedBlockCount([]string{validator.ConsensusAddres}) commision, _ := utils.ParseStringToFloat(validator.Commission.CommissionRate.Rate) @@ -134,17 +133,17 @@ func (r *queryResolver) ValidatorDetail(ctx context.Context, operatorAddress *st func (r *queryResolver) Uptimes(ctx context.Context, operatorAddress *string) (*model.UptimeResult, error) { block, err := document.Block{}.QueryLatestBlockFromDB() if err != nil { - return &model.UptimeResult{}, nil + return &model.UptimeResult{}, err } validator, err := document.GetValidatorByAddr(*operatorAddress) if err != nil { - return &model.UptimeResult{}, nil + return &model.UptimeResult{}, err } missedBlocks, err := document.MissedBlock{}.GetListMissedBlock(block.Height, validator.ConsensusAddres) if err != nil { - return &model.UptimeResult{}, nil + return &model.UptimeResult{}, err } var uptimeList []*model.Uptime for _, missedBlock := range missedBlocks { @@ -164,7 +163,7 @@ func (r *queryResolver) Uptimes(ctx context.Context, operatorAddress *string) (* func (r *queryResolver) ProposedBlocks(ctx context.Context, before *int, size *int, operatorAddress string) ([]*model.Block, error) { blocks, totalRecord, err := document.Block{}.GetBlockListByOffsetAndSizeByOperatorAddress(*before, *size, operatorAddress) if err != nil { - return []*model.Block{}, nil + return []*model.Block{}, err } return document.Block{}.FormatListBlockForModel(blocks, totalRecord) } @@ -172,7 +171,7 @@ func (r *queryResolver) ProposedBlocks(ctx context.Context, before *int, size *i func (r *queryResolver) PowerEvents(ctx context.Context, before *int, size *int, operatorAddress string) ([]*model.PowerEvent, error) { txs, err := document.CommonTx{}.GetListTxByAddress(*before, *size, operatorAddress) if err != nil { - return []*model.PowerEvent{}, nil + return []*model.PowerEvent{}, err } return document.CommonTx{}.FormatListTxsForModelPowerEvent(txs, operatorAddress) } @@ -180,11 +179,11 @@ func (r *queryResolver) PowerEvents(ctx context.Context, before *int, size *int, func (r *queryResolver) AccountTransactions(ctx context.Context, accAddress string, before int, size int) ([]*model.Tx, error) { listTxHash, err := document.AccountTransaction{}.GetListTxsByAddress(before, size, accAddress) if err != nil { - return []*model.Tx{}, nil + return []*model.Tx{}, err } txs, err := document.CommonTx{}.QueryByListByTxhash(listTxHash) if err != nil { - return []*model.Tx{}, nil + return []*model.Tx{}, err } return document.CommonTx{}.FormatListTxsForModel(txs) } @@ -196,18 +195,18 @@ func (r *queryResolver) AccountDetail(ctx context.Context, accAddress string) (* return &model.AccountDetail{ IsValidator: false, OperatorAddress: operatorAddress, - }, nil + }, err } return &model.AccountDetail{ IsValidator: true, OperatorAddress: operatorAddress, - }, nil + }, err } func (r *queryResolver) Proposals(ctx context.Context) ([]*model.Proposal, error) { proposals, err := document.Proposal{}.GetList() if err != nil { - return []*model.Proposal{}, nil + return []*model.Proposal{}, err } return document.Proposal{}.FormatListProposalForModel(proposals) } @@ -230,22 +229,22 @@ func (r *queryResolver) ProposalDetail(ctx context.Context, proposalID int) (*mo func (r *queryResolver) Status(ctx context.Context) (*model.Status, error) { blocks, err := document.Block{}.QueryBlockOrderByHeightDesc(2) if err != nil { - return &model.Status{}, nil + return &model.Status{}, err } bondedToken, err := document.Validator{}.GetSumBondedToken() if err != nil { - return &model.Status{}, nil + return &model.Status{}, err } totalNumTxs, err := document.Block{}.GetCountTxs() if err != nil { - return &model.Status{}, nil + return &model.Status{}, err } totalSupplyToken, err := client.GetSupply() if err != nil { - return &model.Status{}, nil + return &model.Status{}, err } BlockTime := blocks[0].Time.UnixNano() - blocks[1].Time.UnixNano() @@ -279,7 +278,7 @@ func (r *queryResolver) Commission(ctx context.Context, operatorAddress string) func (r *queryResolver) Delegations(ctx context.Context, accAddress string) ([]*model.Delegation, error) { delegationResult, err := client.GetDelegation(accAddress) if err != nil { - return []*model.Delegation{}, nil + return []*model.Delegation{}, err } var listDelegation []*model.Delegation @@ -400,7 +399,7 @@ func (r *queryResolver) StatsAssets(ctx context.Context) ([]*model.StatsAsset, e statsAssets, err := document.StatAssetInfoList20Minute{}.GetList() if err != nil { - return []*model.StatsAsset{}, nil + return []*model.StatsAsset{}, err } var listAssets []*model.StatsAsset for _, item := range statsAssets { @@ -419,7 +418,7 @@ func (r *queryResolver) StatsAssets(ctx context.Context) ([]*model.StatsAsset, e func (r *queryResolver) Delegators(ctx context.Context, operatorAddress string, offset int) (*model.DelegatorResponse, error) { delegationResult, err := client.GetDelegators(operatorAddress, offset) if err != nil { - return &model.DelegatorResponse{}, nil + return &model.DelegatorResponse{}, err } var delegators []*model.Delegator @@ -445,7 +444,7 @@ func (r *queryResolver) Delegators(ctx context.Context, operatorAddress string, func (r *queryResolver) Codes(ctx context.Context, after int, size int) ([]*model.Code, error) { result, err := document.Code{}.GetCodeListByOffsetAndSize(after, size) if err != nil { - return []*model.Code{}, nil + return []*model.Code{}, err } return document.Code{}.FormatForModel(result) } @@ -453,7 +452,7 @@ func (r *queryResolver) Codes(ctx context.Context, after int, size int) ([]*mode func (r *queryResolver) CodeDetail(ctx context.Context, codeID int) (*model.Code, error) { code, err := document.Code{}.FindByCodeId(codeID) if err != nil { - return &model.Code{}, nil + return &model.Code{}, err } return document.Code{}.FormatModelCodeItem(code), nil } @@ -461,11 +460,19 @@ func (r *queryResolver) CodeDetail(ctx context.Context, codeID int) (*model.Code func (r *queryResolver) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) { result, err := document.Contract{}.GetContractByLimitAndOffset(offset, size, keyword) if err != nil { - return []*model.Contract{}, nil + return []*model.Contract{}, err } return document.Contract{}.FormatForModel(result) } +func (r *queryResolver) ContractDetail(ctx context.Context, contractAddress string) (*model.Contract, error) { + contract, err := document.Contract{}.FindByContractAddress(contractAddress) + if err != nil { + return &model.Contract{}, err + } + return document.Contract{}.FormatBsonMForModelContractDetail(contract) +} + // Query returns generated.QueryResolver implementation. func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } diff --git a/orm/document/contract.go b/orm/document/contract.go index e30ba68..05641f5 100644 --- a/orm/document/contract.go +++ b/orm/document/contract.go @@ -1,17 +1,34 @@ package document import ( + "fmt" "time" "github.com/cosmos-gaminghub/exploder-graphql/graph/model" + "github.com/cosmos-gaminghub/exploder-graphql/orm" "gopkg.in/mgo.v2/bson" ) const ( CollectionContract = "contracts" - ContractAddressField = "contract_address" - ContractLabelField = "label" + ContractAddressField = "contract_address" + ContractTxhashField = "txhash" + ContractLabelField = "label" + ContractCodeIdFieled = "code_id" + ContractField = "contract" + ContractAdminField = "admin" + ContractCreatorField = "creator" + ContractExecutedCountField = "executed_count" + ContractInstantiatedAtField = "instantiated_at" + ContractPermissionField = "permission" + ContractPermittedAddressField = "permitted_address" + ContractLastExecutedAtField = "last_executed_at" + ContractTxHashField = "txhash" + ContractVersionField = "version" + ContractMessagesField = "messages" + + Contract_Field_Tx = "txs" ) type Contract struct { @@ -34,14 +51,54 @@ func (d Contract) Name() string { return CollectionContract } -func (_ Contract) FindByContractAddress(contractAddress string) (Contract, error) { - var contract Contract - condition := bson.M{ - ContractAddressField: contractAddress, +func (_ Contract) FindByContractAddress(contractAddress string) (bson.M, error) { + var query = orm.NewQuery() + defer query.Release() + + var condition = []bson.M{ + { + "$match": bson.M{ + ContractAddressField: contractAddress, + }, + }, + { + "$lookup": bson.M{ + "from": CollectionNmCommonTx, + "localField": ContractTxhashField, + "foreignField": Tx_Field_Hash, + "as": Contract_Field_Tx, + }, + }, + { + "$unwind": "$" + Contract_Field_Tx, + }, + { + "$project": bson.M{ + "messages": "$" + Contract_Field_Tx + ".messages", + "code_id": 1, + "contract": 1, + "contract_address": 1, + "admin": 1, + "creator": 1, + "executed_count": 1, + "instantiated_at": 1, + "label": 1, + "last_executed_at": 1, + "permission": 1, + "permitted_address": 1, + "txhash": 1, + "version": 1, + }, + }, } - err := queryOne(CollectionContract, nil, condition, &contract) - return contract, err + result := bson.M{} + err := query.SetResult(&result). + SetCollection(CollectionContract). + PipeQuery( + condition, + ) + return result, err } func (_ Contract) GetContractByLimitAndOffset(offset int, size int, keyword *string) ([]Contract, error) { @@ -61,18 +118,41 @@ func (_ Contract) GetContractByLimitAndOffset(offset int, size int, keyword *str func (_ Contract) FormatForModel(result []Contract) ([]*model.Contract, error) { var listContract []*model.Contract for _, item := range result { - listContract = append(listContract, &model.Contract{ - CodeID: item.CodeId, - ContractAddress: item.ContractAddress, - Label: item.Label, - Contract: item.Contract, - Creator: item.Creator, - ExecutedCount: item.ExecutedCount, - InstantiatedAt: item.InstantiatedAt.String(), - LastExecutedAt: item.LastExecutedAt.String(), - Txhash: item.TxHash, - Version: item.Version, - }) + listContract = append(listContract, Contract{}.FormatForModelItem(item)) } return listContract, nil } + +func (_ Contract) FormatForModelItem(item Contract) *model.Contract { + return &model.Contract{ + CodeID: item.CodeId, + ContractAddress: item.ContractAddress, + Label: item.Label, + Contract: item.Contract, + Creator: item.Creator, + ExecutedCount: item.ExecutedCount, + InstantiatedAt: item.InstantiatedAt.String(), + LastExecutedAt: item.LastExecutedAt.String(), + Txhash: item.TxHash, + Version: item.Version, + } +} + +func (_ Contract) FormatBsonMForModelContractDetail(result bson.M) (*model.Contract, error) { + return &model.Contract{ + CodeID: int(result[ContractCodeIdFieled].(int)), + Contract: fmt.Sprintf("%v", result[ContractField]), + ContractAddress: fmt.Sprintf("%v", result[ContractAddressField]), + Admin: fmt.Sprintf("%v", result[ContractAdminField]), + Creator: fmt.Sprintf("%v", result[ContractCreatorField]), + ExecutedCount: int(result[ContractExecutedCountField].(int)), + InstantiatedAt: fmt.Sprintf("%v", result[ContractInstantiatedAtField]), + Label: fmt.Sprintf("%v", result[ContractLabelField]), + LastExecutedAt: fmt.Sprintf("%v", result[ContractLastExecutedAtField]), + Permission: fmt.Sprintf("%v", result[ContractPermissionField]), + PermittedAddress: fmt.Sprintf("%v", result[ContractPermittedAddressField]), + Txhash: fmt.Sprintf("%v", result[ContractTxHashField]), + Version: fmt.Sprintf("%v", result[ContractVersionField]), + Messages: fmt.Sprintf("%v", result[ContractMessagesField]), + }, nil +} From e4f5ee952c8b7f7fe880507ea1b1a1d401b328dd Mon Sep 17 00:00:00 2001 From: HoangPham Date: Wed, 25 May 2022 16:58:55 +0700 Subject: [PATCH 3/6] Update get code transactions --- graph/generated/generated.go | 108 ++++++++++++++++++++++++++++ graph/schema.graphqls | 5 ++ graph/schema.resolvers.go | 19 +++++ orm/document/account_transaction.go | 22 ++++++ 4 files changed, 154 insertions(+) diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 2e8e57c..4b2b63e 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -216,6 +216,7 @@ type ComplexityRoot struct { BlockTxs func(childComplexity int, height *int) int Blocks func(childComplexity int, offset *int, size *int) int CodeDetail func(childComplexity int, codeID int) int + CodeTransactions func(childComplexity int, codeID int, before int, size int) int Codes func(childComplexity int, after int, size int) int Commission func(childComplexity int, operatorAddress string) int ContractDetail func(childComplexity int, contractAddress string) int @@ -405,6 +406,7 @@ type QueryResolver interface { Delegators(ctx context.Context, operatorAddress string, offset int) (*model.DelegatorResponse, error) Codes(ctx context.Context, after int, size int) ([]*model.Code, error) CodeDetail(ctx context.Context, codeID int) (*model.Code, error) + CodeTransactions(ctx context.Context, codeID int, before int, size int) ([]*model.Tx, error) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) ContractDetail(ctx context.Context, contractAddress string) (*model.Contract, error) } @@ -1187,6 +1189,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.CodeDetail(childComplexity, args["code_id"].(int)), true + case "Query.code_transactions": + if e.complexity.Query.CodeTransactions == nil { + break + } + + args, err := ec.field_Query_code_transactions_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.CodeTransactions(childComplexity, args["code_id"].(int), args["before"].(int), args["size"].(int)), true + case "Query.codes": if e.complexity.Query.Codes == nil { break @@ -2403,6 +2417,11 @@ type Query { """ code_detail(code_id: Int!): Code! + """ + Get code transactions + """ + code_transactions(code_id: Int!, before: Int!, size: Int!): [Tx!]! + """ Get list contract """ @@ -2568,6 +2587,39 @@ func (ec *executionContext) field_Query_code_detail_args(ctx context.Context, ra return args, nil } +func (ec *executionContext) field_Query_code_transactions_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["code_id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("code_id")) + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["code_id"] = arg0 + var arg1 int + if tmp, ok := rawArgs["before"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("before")) + arg1, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["before"] = arg1 + var arg2 int + if tmp, ok := rawArgs["size"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("size")) + arg2, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["size"] = arg2 + return args, nil +} + func (ec *executionContext) field_Query_codes_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -7541,6 +7593,48 @@ func (ec *executionContext) _Query_code_detail(ctx context.Context, field graphq return ec.marshalNCode2ᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐCode(ctx, field.Selections, res) } +func (ec *executionContext) _Query_code_transactions(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_code_transactions_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().CodeTransactions(rctx, args["code_id"].(int), args["before"].(int), args["size"].(int)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Tx) + fc.Result = res + return ec.marshalNTx2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐTxᚄ(ctx, field.Selections, res) +} + func (ec *executionContext) _Query_contracts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -12801,6 +12895,20 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } return res }) + case "code_transactions": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_code_transactions(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) case "contracts": field := field out.Concurrently(i, func() (res graphql.Marshaler) { diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 02ac5dd..8a594fb 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -376,6 +376,11 @@ type Query { """ code_detail(code_id: Int!): Code! + """ + Get code transactions + """ + code_transactions(code_id: Int!, before: Int!, size: Int!): [Tx!]! + """ Get list contract """ diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 5f41f38..3111e40 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -457,6 +457,25 @@ func (r *queryResolver) CodeDetail(ctx context.Context, codeID int) (*model.Code return document.Code{}.FormatModelCodeItem(code), nil } +func (r *queryResolver) CodeTransactions(ctx context.Context, codeID int, before int, size int) ([]*model.Tx, error) { + contracts, err := document.Contract{}.GetContractByCodeId(codeID) + if err != nil { + return []*model.Tx{}, err + } + + listContractAddress := document.Contract{}.GetListContractAddressFromBson(contracts) + listTxHash, err := document.AccountTransaction{}.GetListTxsInAddress(before, size, listContractAddress) + if err != nil { + return []*model.Tx{}, err + } + + txs, err := document.CommonTx{}.QueryByListByTxhash(listTxHash) + if err != nil { + return []*model.Tx{}, err + } + return document.CommonTx{}.FormatListTxsForModel(txs) +} + func (r *queryResolver) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) { result, err := document.Contract{}.GetContractByLimitAndOffset(offset, size, keyword) if err != nil { diff --git a/orm/document/account_transaction.go b/orm/document/account_transaction.go index 785d519..1cb32fd 100644 --- a/orm/document/account_transaction.go +++ b/orm/document/account_transaction.go @@ -37,3 +37,25 @@ func (_ AccountTransaction) GetListTxsByAddress(before int, size int, address st } return listTxHash, err } + +func (_ AccountTransaction) GetListTxsInAddress(before int, size int, address []string) (listTxHash []string, err error) { + var data []AccountTransaction + + selector := bson.M{ + AccountTransaction_Txhash: 1, + } + query := bson.M{AccountTransaction_Account_Address: bson.M{ + "$in": address, + }} + if before != 0 { + query[AccountTransaction_Field_Height] = bson.M{ + "$lt": before, + } + } + + err = querylistByOffsetAndSize(CollectionAccountTransaction, selector, query, desc(AccountTransaction_Field_Height), 0, size, &data) + for _, item := range data { + listTxHash = append(listTxHash, item.TxHash) + } + return listTxHash, err +} From bfd54b58e33c734d31d5418e3b504393544f9653 Mon Sep 17 00:00:00 2001 From: HoangPham Date: Wed, 25 May 2022 17:03:13 +0700 Subject: [PATCH 4/6] Update get code tx --- orm/document/contract.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/orm/document/contract.go b/orm/document/contract.go index 05641f5..7de74ff 100644 --- a/orm/document/contract.go +++ b/orm/document/contract.go @@ -115,6 +115,25 @@ func (_ Contract) GetContractByLimitAndOffset(offset int, size int, keyword *str return data, err } +func (_ Contract) GetContractByCodeId(codeId int) ([]bson.M, error) { + query := bson.M{} + query[ContractCodeIdFieled] = codeId + + data := []bson.M{} + var selector = bson.M{ + ContractAddressField: 1, + } + err := queryAll(CollectionContract, selector, query, "", 0, &data) + return data, err +} + +func (_ Contract) GetListContractAddressFromBson(bson []bson.M) (result []string) { + for _, item := range bson { + result = append(result, item[ContractAddressField].(string)) + } + return result +} + func (_ Contract) FormatForModel(result []Contract) ([]*model.Contract, error) { var listContract []*model.Contract for _, item := range result { From d0a9726bd3c7a1f07686fdf498056dd34f019a94 Mon Sep 17 00:00:00 2001 From: HoangPham Date: Wed, 25 May 2022 17:18:01 +0700 Subject: [PATCH 5/6] Update get code contracts --- graph/generated/generated.go | 108 +++++++++++++++++++++++++++++++++++ graph/schema.graphqls | 5 ++ graph/schema.resolvers.go | 8 +++ orm/document/contract.go | 12 ++++ 4 files changed, 133 insertions(+) diff --git a/graph/generated/generated.go b/graph/generated/generated.go index 4b2b63e..ac36d63 100644 --- a/graph/generated/generated.go +++ b/graph/generated/generated.go @@ -215,6 +215,7 @@ type ComplexityRoot struct { BlockDetail func(childComplexity int, height *int) int BlockTxs func(childComplexity int, height *int) int Blocks func(childComplexity int, offset *int, size *int) int + CodeContracts func(childComplexity int, codeID int, offset int, size int) int CodeDetail func(childComplexity int, codeID int) int CodeTransactions func(childComplexity int, codeID int, before int, size int) int Codes func(childComplexity int, after int, size int) int @@ -407,6 +408,7 @@ type QueryResolver interface { Codes(ctx context.Context, after int, size int) ([]*model.Code, error) CodeDetail(ctx context.Context, codeID int) (*model.Code, error) CodeTransactions(ctx context.Context, codeID int, before int, size int) ([]*model.Tx, error) + CodeContracts(ctx context.Context, codeID int, offset int, size int) ([]*model.Contract, error) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) ContractDetail(ctx context.Context, contractAddress string) (*model.Contract, error) } @@ -1177,6 +1179,18 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Query.Blocks(childComplexity, args["offset"].(*int), args["size"].(*int)), true + case "Query.code_contracts": + if e.complexity.Query.CodeContracts == nil { + break + } + + args, err := ec.field_Query_code_contracts_args(context.TODO(), rawArgs) + if err != nil { + return 0, false + } + + return e.complexity.Query.CodeContracts(childComplexity, args["code_id"].(int), args["offset"].(int), args["size"].(int)), true + case "Query.code_detail": if e.complexity.Query.CodeDetail == nil { break @@ -2422,6 +2436,11 @@ type Query { """ code_transactions(code_id: Int!, before: Int!, size: Int!): [Tx!]! + """ + Get code contracts + """ + code_contracts(code_id: Int!, offset: Int!, size: Int!): [Contract!]! + """ Get list contract """ @@ -2572,6 +2591,39 @@ func (ec *executionContext) field_Query_blocks_args(ctx context.Context, rawArgs return args, nil } +func (ec *executionContext) field_Query_code_contracts_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { + var err error + args := map[string]interface{}{} + var arg0 int + if tmp, ok := rawArgs["code_id"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("code_id")) + arg0, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["code_id"] = arg0 + var arg1 int + if tmp, ok := rawArgs["offset"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("offset")) + arg1, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["offset"] = arg1 + var arg2 int + if tmp, ok := rawArgs["size"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("size")) + arg2, err = ec.unmarshalNInt2int(ctx, tmp) + if err != nil { + return nil, err + } + } + args["size"] = arg2 + return args, nil +} + func (ec *executionContext) field_Query_code_detail_args(ctx context.Context, rawArgs map[string]interface{}) (map[string]interface{}, error) { var err error args := map[string]interface{}{} @@ -7635,6 +7687,48 @@ func (ec *executionContext) _Query_code_transactions(ctx context.Context, field return ec.marshalNTx2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐTxᚄ(ctx, field.Selections, res) } +func (ec *executionContext) _Query_code_contracts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + rawArgs := field.ArgumentMap(ec.Variables) + args, err := ec.field_Query_code_contracts_args(ctx, rawArgs) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + fc.Args = args + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().CodeContracts(rctx, args["code_id"].(int), args["offset"].(int), args["size"].(int)) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.([]*model.Contract) + fc.Result = res + return ec.marshalNContract2ᚕᚖgithubᚗcomᚋcosmosᚑgaminghubᚋexploderᚑgraphqlᚋgraphᚋmodelᚐContractᚄ(ctx, field.Selections, res) +} + func (ec *executionContext) _Query_contracts(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -12909,6 +13003,20 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr } return res }) + case "code_contracts": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_code_contracts(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) case "contracts": field := field out.Concurrently(i, func() (res graphql.Marshaler) { diff --git a/graph/schema.graphqls b/graph/schema.graphqls index 8a594fb..356f5d0 100644 --- a/graph/schema.graphqls +++ b/graph/schema.graphqls @@ -381,6 +381,11 @@ type Query { """ code_transactions(code_id: Int!, before: Int!, size: Int!): [Tx!]! + """ + Get code contracts + """ + code_contracts(code_id: Int!, offset: Int!, size: Int!): [Contract!]! + """ Get list contract """ diff --git a/graph/schema.resolvers.go b/graph/schema.resolvers.go index 3111e40..fd07a7a 100644 --- a/graph/schema.resolvers.go +++ b/graph/schema.resolvers.go @@ -476,6 +476,14 @@ func (r *queryResolver) CodeTransactions(ctx context.Context, codeID int, before return document.CommonTx{}.FormatListTxsForModel(txs) } +func (r *queryResolver) CodeContracts(ctx context.Context, codeID int, offset int, size int) ([]*model.Contract, error) { + result, err := document.Contract{}.GetContractPaginationByCodeId(offset, size, codeID) + if err != nil { + return []*model.Contract{}, err + } + return document.Contract{}.FormatForModel(result) +} + func (r *queryResolver) Contracts(ctx context.Context, offset int, size int, keyword *string) ([]*model.Contract, error) { result, err := document.Contract{}.GetContractByLimitAndOffset(offset, size, keyword) if err != nil { diff --git a/orm/document/contract.go b/orm/document/contract.go index 7de74ff..eec76c9 100644 --- a/orm/document/contract.go +++ b/orm/document/contract.go @@ -115,6 +115,17 @@ func (_ Contract) GetContractByLimitAndOffset(offset int, size int, keyword *str return data, err } +// Get contract with offset and size by code id +func (_ Contract) GetContractPaginationByCodeId(offset int, size int, codeId int) ([]Contract, error) { + query := bson.M{} + query[ContractCodeIdFieled] = codeId + + data := []Contract{} + err := querylistByOffsetAndSize(CollectionContract, nil, query, "", offset, size, &data) + return data, err +} + +// Get only contract address by code id func (_ Contract) GetContractByCodeId(codeId int) ([]bson.M, error) { query := bson.M{} query[ContractCodeIdFieled] = codeId @@ -127,6 +138,7 @@ func (_ Contract) GetContractByCodeId(codeId int) ([]bson.M, error) { return data, err } +// Get list contract address from list bson.M func (_ Contract) GetListContractAddressFromBson(bson []bson.M) (result []string) { for _, item := range bson { result = append(result, item[ContractAddressField].(string)) From ddcf2bb79eaa1333a3be645b9ce22b88ac6d462d Mon Sep 17 00:00:00 2001 From: HoangPham Date: Wed, 1 Jun 2022 09:37:59 +0700 Subject: [PATCH 6/6] Update api --- orm/document/contract.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/orm/document/contract.go b/orm/document/contract.go index eec76c9..0d54d2b 100644 --- a/orm/document/contract.go +++ b/orm/document/contract.go @@ -28,7 +28,7 @@ const ( ContractVersionField = "version" ContractMessagesField = "messages" - Contract_Field_Tx = "txs" + Contract_Tx_Collection = "txs" ) type Contract struct { @@ -66,15 +66,12 @@ func (_ Contract) FindByContractAddress(contractAddress string) (bson.M, error) "from": CollectionNmCommonTx, "localField": ContractTxhashField, "foreignField": Tx_Field_Hash, - "as": Contract_Field_Tx, + "as": Contract_Tx_Collection, }, }, - { - "$unwind": "$" + Contract_Field_Tx, - }, { "$project": bson.M{ - "messages": "$" + Contract_Field_Tx + ".messages", + "messages": "$" + Contract_Tx_Collection + ".messages", "code_id": 1, "contract": 1, "contract_address": 1,