Batch minting (#30)
* Bach Mint * Add mint_for for batch minting * Batch minting with mint to function with given number * Minor fixes * Update components/collections/actions/actions.ts Co-authored-by: name-user1 <eray@deuslabs.fi> Co-authored-by: Serkan Reis <serkanreis@gmail.com> Co-authored-by: Arda Nakışçı <anakisci@gmail.com>
This commit is contained in:
co-authored by
name-user1
Serkan Reis
Arda Nakışçı
parent
823b8c04f5
commit
c994411dfb
@@ -1,8 +1,10 @@
|
||||
import type { SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
||||
import type { MsgExecuteContractEncodeObject, SigningCosmWasmClient } from '@cosmjs/cosmwasm-stargate'
|
||||
import { toUtf8 } from '@cosmjs/encoding'
|
||||
import type { Coin } from '@cosmjs/proto-signing'
|
||||
import { coin } from '@cosmjs/proto-signing'
|
||||
import type { logs } from '@cosmjs/stargate'
|
||||
import type { Timestamp } from '@stargazezone/types/contracts/minter/shared-types'
|
||||
import { MsgExecuteContract } from 'cosmjs-types/cosmwasm/wasm/v1/tx'
|
||||
|
||||
export interface InstantiateResponse {
|
||||
readonly contractAddress: string
|
||||
@@ -32,6 +34,7 @@ export interface MinterInstance {
|
||||
updatePerAddressLimit: (senderAddress: string, perAddressLimit: number) => Promise<string>
|
||||
mintTo: (senderAddress: string, recipient: string) => Promise<string>
|
||||
mintFor: (senderAddress: string, recipient: string, tokenId: number) => Promise<string>
|
||||
batchMint: (senderAddress: string, recipient: string, batchNumber: number) => Promise<string>
|
||||
shuffle: (senderAddress: string) => Promise<string>
|
||||
withdraw: (senderAddress: string) => Promise<string>
|
||||
}
|
||||
@@ -43,6 +46,7 @@ export interface MinterMessages {
|
||||
updatePerAddressLimit: (contractAddress: string, perAddressLimit: number) => UpdatePerAddressLimitMessage
|
||||
mintTo: (contractAddress: string, recipient: string) => MintToMessage
|
||||
mintFor: (contractAddress: string, recipient: string, tokenId: number) => MintForMessage
|
||||
batchMint: (contractAddress: string, recipient: string, batchNumber: number) => BatchMintMessage
|
||||
shuffle: (contractAddress: string) => ShuffleMessage
|
||||
withdraw: (contractAddress: string) => WithdrawMessage
|
||||
}
|
||||
@@ -110,6 +114,13 @@ export interface MintForMessage {
|
||||
funds: Coin[]
|
||||
}
|
||||
|
||||
export interface BatchMintMessage {
|
||||
sender: string
|
||||
contract: string
|
||||
msg: Record<string, unknown>[]
|
||||
funds: Coin[]
|
||||
}
|
||||
|
||||
export interface ShuffleMessage {
|
||||
sender: string
|
||||
contract: string
|
||||
@@ -267,6 +278,29 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
|
||||
return res.transactionHash
|
||||
}
|
||||
|
||||
const batchMint = async (senderAddress: string, recipient: string, batchNumber: number): Promise<string> => {
|
||||
const executeContractMsgs: MsgExecuteContractEncodeObject[] = []
|
||||
for (let i = 0; i < batchNumber; i++) {
|
||||
const msg = {
|
||||
mint_to: { recipient },
|
||||
}
|
||||
const executeContractMsg: MsgExecuteContractEncodeObject = {
|
||||
typeUrl: '/cosmwasm.wasm.v1.MsgExecuteContract',
|
||||
value: MsgExecuteContract.fromPartial({
|
||||
sender: senderAddress,
|
||||
contract: contractAddress,
|
||||
msg: toUtf8(JSON.stringify(msg)),
|
||||
}),
|
||||
}
|
||||
|
||||
executeContractMsgs.push(executeContractMsg)
|
||||
}
|
||||
|
||||
const res = await client.signAndBroadcast(senderAddress, executeContractMsgs, 'auto', 'batch mint')
|
||||
|
||||
return res.transactionHash
|
||||
}
|
||||
|
||||
const shuffle = async (senderAddress: string): Promise<string> => {
|
||||
const res = await client.execute(
|
||||
senderAddress,
|
||||
@@ -308,6 +342,7 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
|
||||
updatePerAddressLimit,
|
||||
mintTo,
|
||||
mintFor,
|
||||
batchMint,
|
||||
shuffle,
|
||||
withdraw,
|
||||
}
|
||||
@@ -406,6 +441,19 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
|
||||
}
|
||||
}
|
||||
|
||||
const batchMint = (contractAddress: string, recipient: string, batchNumber: number): BatchMintMessage => {
|
||||
const msg: Record<string, unknown>[] = []
|
||||
for (let i = 0; i < batchNumber; i++) {
|
||||
msg.push({ mint_to: { recipient } })
|
||||
}
|
||||
return {
|
||||
sender: txSigner,
|
||||
contract: contractAddress,
|
||||
msg,
|
||||
funds: [],
|
||||
}
|
||||
}
|
||||
|
||||
const shuffle = (contractAddress: string): ShuffleMessage => {
|
||||
return {
|
||||
sender: txSigner,
|
||||
@@ -435,6 +483,7 @@ export const minter = (client: SigningCosmWasmClient, txSigner: string): MinterC
|
||||
updatePerAddressLimit,
|
||||
mintTo,
|
||||
mintFor,
|
||||
batchMint,
|
||||
shuffle,
|
||||
withdraw,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user