Skip to content

Commit

Permalink
feat: Support 'contracts-body' flag on the 'batch-create-contract' co…
Browse files Browse the repository at this point in the history
…mmand
  • Loading branch information
Mahmoud-Emad committed Sep 26, 2024
1 parent f363a94 commit f1442cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 5 additions & 0 deletions griddriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@ func main() {
Usage: "json encoding of list of substrate BatchCreateContractData objects",
Required: true,
},
cli.StringFlag{
Name: "contracts-body",
Usage: "deployment body string",
Required: true,
},
},
Action: substrateDecorator(batchAllCreateContract),
},
Expand Down
9 changes: 8 additions & 1 deletion griddriver/substrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,20 @@ func signDeployment(ctx *cli.Context, sub *substrate.Substrate, identity substra
}

func batchAllCreateContract(ctx *cli.Context, sub *substrate.Substrate, identity substrate.Identity) (interface{}, error) {
body := ctx.String("contracts-body")
data := []byte(ctx.String("contracts-data"))

contractData := []substrate.BatchCreateContractData{}
if err := json.Unmarshal(data, &contractData); err != nil {
return nil, fmt.Errorf("failed to decode contract data: %w", err)
}

for id := range contractData {
if contractData[id].Name == "" {
contractData[id].Body = body
}
}

contractIds, err := sub.BatchAllCreateContract(identity, contractData)
if err != nil {
return nil, fmt.Errorf("failed to create contracts: %w", err)
Expand All @@ -169,7 +176,7 @@ func batchAllCreateContract(ctx *cli.Context, sub *substrate.Substrate, identity
return nil, fmt.Errorf("failed to encode contract ids: %w", err)
}

return ret, nil
return string(ret), nil
}

func batchCancelContract(ctx *cli.Context, sub *substrate.Substrate, identity substrate.Identity) (interface{}, error) {
Expand Down

0 comments on commit f1442cf

Please sign in to comment.