@0x/contracts-erc1155
: Add mintKnownFungibleTokensAsync()
, isNonFungibleItemAsync()
, isFungibleItemAsync()
, getOwnerOfAsync()
, getBalanceAsync()
to Erc1155Wrapper
.
This commit is contained in:
committed by
Amir Bandeali
parent
348ec5bc3c
commit
741fdfa52e
@@ -80,20 +80,28 @@ export class Erc1155Wrapper {
|
||||
);
|
||||
// tslint:disable-next-line no-unnecessary-type-assertion
|
||||
const createFungibleTokenLog = tx.logs[0] as LogWithDecodedArgs<ERC1155TransferSingleEventArgs>;
|
||||
const token = createFungibleTokenLog.args.id;
|
||||
const tokenId = createFungibleTokenLog.args.id;
|
||||
await this.mintKnownFungibleTokensAsync(tokenId, beneficiaries, tokenAmounts);
|
||||
return tokenId;
|
||||
}
|
||||
public async mintKnownFungibleTokensAsync(
|
||||
tokenId: BigNumber,
|
||||
beneficiaries: string[],
|
||||
tokenAmounts: BigNumber | BigNumber[],
|
||||
): Promise<void> {
|
||||
const tokenAmountsAsArray = _.isArray(tokenAmounts) ? tokenAmounts : [];
|
||||
if (!_.isArray(tokenAmounts)) {
|
||||
_.each(_.range(0, beneficiaries.length), () => {
|
||||
tokenAmountsAsArray.push(tokenAmounts);
|
||||
});
|
||||
}
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await this._erc1155Contract.mintFungible.sendTransactionAsync(token, beneficiaries, tokenAmountsAsArray, {
|
||||
from: this._contractOwner,
|
||||
}),
|
||||
await this._erc1155Contract.mintFungible.awaitTransactionSuccessAsync(
|
||||
tokenId,
|
||||
beneficiaries,
|
||||
tokenAmountsAsArray,
|
||||
{ from: this._contractOwner },
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
return token;
|
||||
}
|
||||
public async mintNonFungibleTokensAsync(beneficiaries: string[]): Promise<[BigNumber, BigNumber[]]> {
|
||||
const tokenUri = 'dummyNonFungibleToken';
|
||||
@@ -106,10 +114,10 @@ export class Erc1155Wrapper {
|
||||
// tslint:disable-next-line no-unnecessary-type-assertion
|
||||
const createFungibleTokenLog = tx.logs[0] as LogWithDecodedArgs<ERC1155TransferSingleEventArgs>;
|
||||
const token = createFungibleTokenLog.args.id;
|
||||
await this._web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await this._erc1155Contract.mintNonFungible.sendTransactionAsync(token, beneficiaries, {
|
||||
from: this._contractOwner,
|
||||
}),
|
||||
await this._erc1155Contract.mintNonFungible.awaitTransactionSuccessAsync(
|
||||
token,
|
||||
beneficiaries,
|
||||
{ from: this._contractOwner },
|
||||
constants.AWAIT_TRANSACTION_MINED_MS,
|
||||
);
|
||||
const encodedNftIds: BigNumber[] = [];
|
||||
@@ -156,4 +164,19 @@ export class Erc1155Wrapper {
|
||||
expect(balance, `${ownersExtended[i]}${tokensExtended[i]}`).to.be.bignumber.equal(expectedBalances[i]);
|
||||
});
|
||||
}
|
||||
public async isNonFungibleItemAsync(tokenId: BigNumber): Promise<boolean> {
|
||||
return this._erc1155Contract.isNonFungibleItem.callAsync(tokenId);
|
||||
}
|
||||
public async isFungibleItemAsync(tokenId: BigNumber): Promise<boolean> {
|
||||
return !(await this.isNonFungibleItemAsync(tokenId));
|
||||
}
|
||||
public async getOwnerOfAsync(tokenId: BigNumber): Promise<string> {
|
||||
return this._erc1155Contract.ownerOf.callAsync(tokenId);
|
||||
}
|
||||
/**
|
||||
* @dev Get the balance of an ERC1155 token for a given owner and token ID.
|
||||
*/
|
||||
public async getBalanceAsync(ownerAddress: string, tokenId: BigNumber): Promise<BigNumber> {
|
||||
return this._erc1155Contract.balanceOf.callAsync(ownerAddress, tokenId);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user