Skip to content

Commit

Permalink
nft: Batch NFT mint extrinsics (#1576)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdamian authored Feb 14, 2023
1 parent 9bc98a3 commit e09cce1
Show file tree
Hide file tree
Showing 11 changed files with 638 additions and 133 deletions.
2 changes: 2 additions & 0 deletions centchain/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func init() {

var log = logging.Logger("centchain-client")

type CallProviderFn func(metadata *types.Metadata) (*types.Call, error)

// ExtrinsicInfo holds details of a successful extrinsic
type ExtrinsicInfo struct {
Hash types.Hash
Expand Down
2 changes: 0 additions & 2 deletions centchain/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (
"github.com/centrifuge/go-substrate-rpc-client/v4/types"
)

type CallProviderFn func(metadata *types.Metadata) (*types.Call, error)

type TestClient struct {
api *gsrpc.SubstrateAPI
meta *types.Metadata
Expand Down
6 changes: 4 additions & 2 deletions documents/anchor_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ func (a *AnchorJob) loadTasks() {
next: "pre_commit",
},
"pre_commit": {
runnerFunc: func(args []interface{}, overrides map[string]interface{}) (interface{},
error) {
runnerFunc: func(
args []interface{},
overrides map[string]interface{},
) (interface{}, error) {
preCommit := args[2].(bool)
if !preCommit {
return nil, nil
Expand Down
28 changes: 3 additions & 25 deletions identity/v2/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"math/big"
"time"

"github.com/centrifuge/go-centrifuge/pallets/utility"

keystoreTypes "github.com/centrifuge/chain-custom-types/pkg/keystore"
proxyType "github.com/centrifuge/chain-custom-types/pkg/proxy"
"github.com/centrifuge/go-centrifuge/centchain"
Expand Down Expand Up @@ -215,7 +217,7 @@ func ExecutePostAccountBootstrap(

defer testClient.Close()

if _, err = testClient.SubmitAndWait(ctx, originKrp, batchCalls(callCreationFns...)); err != nil {
if _, err = testClient.SubmitAndWait(ctx, originKrp, utility.BatchCalls(callCreationFns...)); err != nil {
return fmt.Errorf("couldn't submit post account bootstrap batch call: %w", err)
}

Expand Down Expand Up @@ -466,27 +468,3 @@ func GetAddKeysCall(
return &proxyCall, nil
}, nil
}

func batchCalls(callCreationFns ...centchain.CallProviderFn) centchain.CallProviderFn {
return func(meta *types.Metadata) (*types.Call, error) {
var calls []*types.Call

for _, callCreationFn := range callCreationFns {
call, err := callCreationFn(meta)

if err != nil {
return nil, fmt.Errorf("couldn't create call: %w", err)
}

calls = append(calls, call)
}

batchCall, err := types.NewCall(meta, "Utility.batch_all", calls)

if err != nil {
return nil, err
}

return &batchCall, nil
}
}
11 changes: 9 additions & 2 deletions nft/v3/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/centrifuge/go-centrifuge/jobs"
"github.com/centrifuge/go-centrifuge/pallets"
"github.com/centrifuge/go-centrifuge/pallets/uniques"
"github.com/centrifuge/go-centrifuge/pallets/utility"
"github.com/centrifuge/go-centrifuge/pending"
)

Expand Down Expand Up @@ -54,20 +55,26 @@ func (*Bootstrapper) Bootstrap(ctx map[string]interface{}) error {
return errors.New("proxy API not initialised")
}

utilityAPI, ok := ctx[pallets.BootstrappedUtilityAPI].(utility.API)

if !ok {
return errors.New("utility API not initialised")
}

go dispatcher.RegisterRunner(commitAndMintNFTV3Job, &CommitAndMintNFTJobRunner{
accountsSrv: accountsSrv,
pendingDocsSrv: pendingDocsSrv,
docSrv: docSrv,
dispatcher: dispatcher,
api: uniquesAPI,
utilityAPI: utilityAPI,
ipfsPinningSrv: ipfsPinningSrv,
})

go dispatcher.RegisterRunner(mintNFTV3Job, &MintNFTJobRunner{
accountsSrv: accountsSrv,
docSrv: docSrv,
dispatcher: dispatcher,
api: uniquesAPI,
utilityAPI: utilityAPI,
ipfsPinningSrv: ipfsPinningSrv,
})

Expand Down
Loading

0 comments on commit e09cce1

Please sign in to comment.