Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func mint(
- ctx context.Context,
- wallet *tonWallet.Wallet,
- api ton.APIClientWrapped,
- collectionAddr *address.Address,
- owner *address.Address,
- ) (*address.Address, int64, error) {
- collectionClient := nft.NewCollectionClient(api, collectionAddr)
- collectionData, err := collectionClient.GetCollectionData(ctx)
- if err != nil {
- return nil, 0, fmt.Errorf("GetCollectionData: %w", err)
- }
- if collectionData.NextItemIndex.Int64() > max {
- return nil, collectionData.NextItemIndex.Int64(), nil
- }
- nftAddr, err := collectionClient.GetNFTAddressByIndex(ctx, collectionData.NextItemIndex)
- if err != nil {
- return nil, 0, fmt.Errorf("GetNFTAddressByIndex: %w", err)
- }
- mintData, err := collectionClient.BuildMintPayload(
- collectionData.NextItemIndex,
- owner,
- tlb.MustFromTON("0.01"),
- &nft.ContentOffchain{
- URI: fmt.Sprint(collectionData.NextItemIndex) + ".json",
- },
- )
- if err != nil {
- return nil, 0, fmt.Errorf("BuildMintPayload: %w", err)
- }
- mintMsg := tonWallet.SimpleMessage(collectionAddr, tlb.MustFromTON("0.025"), mintData)
- if err := wallet.Send(ctx, mintMsg, true); err != nil {
- return nil, 0, fmt.Errorf("Send: %w", err)
- }
- // Additional check
- // itemClient := nft.NewItemClient(api, nftAddr)
- // newData, err := retry.WithValueTon(ctx, func() (*nft.ItemData, error) {
- // d, err := itemClient.GetNFTData(ctx)
- // if err != nil {
- // return nil, err
- // }
- // if d == nil {
- // return nil, fmt.Errorf("nil")
- // }
- // return d, nil
- // })
- // if err != nil {
- // return nil, fmt.Errorf("GetNFTData: %w", err)
- // }
- // if newData.Index != collectionData.NextItemIndex {
- // panic("not minted")
- // }
- return nftAddr, collectionData.NextItemIndex.Int64(), nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement