mainnet-js 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.html +1 -1
- package/dist/{mainnet-1.1.0.js → mainnet-1.1.1.js} +2 -2
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +7 -7
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +6 -2
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +10 -4
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transaction/Wif.ts +10 -9
- package/src/wallet/Cashtokens.test.headless.js +1 -1
- package/src/wallet/Cashtokens.test.ts +189 -1
- package/src/wallet/Wif.ts +24 -6
package/src/wallet/Wif.ts
CHANGED
|
@@ -1481,6 +1481,10 @@ export class Wallet extends BaseWallet {
|
|
|
1481
1481
|
mintRequests: TokenMintRequest | Array<TokenMintRequest>,
|
|
1482
1482
|
deductTokenAmount: boolean = false
|
|
1483
1483
|
): Promise<SendResponse> {
|
|
1484
|
+
if (tokenId?.length !== 64) {
|
|
1485
|
+
throw Error(`Invalid tokenId supplied: ${tokenId}`);
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1484
1488
|
if (!Array.isArray(mintRequests)) {
|
|
1485
1489
|
mintRequests = [mintRequests];
|
|
1486
1490
|
}
|
|
@@ -1550,6 +1554,10 @@ export class Wallet extends BaseWallet {
|
|
|
1550
1554
|
burnRequest: TokenBurnRequest,
|
|
1551
1555
|
message?: string
|
|
1552
1556
|
): Promise<SendResponse> {
|
|
1557
|
+
if (burnRequest.tokenId?.length !== 64) {
|
|
1558
|
+
throw Error(`Invalid tokenId supplied: ${burnRequest.tokenId}`);
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1553
1561
|
const utxos = await this.getAddressUtxos(this.cashaddr!);
|
|
1554
1562
|
const tokenUtxos = utxos.filter(
|
|
1555
1563
|
(val) =>
|
|
@@ -1641,7 +1649,9 @@ export class Wallet extends BaseWallet {
|
|
|
1641
1649
|
* @returns {number} fungible token balance
|
|
1642
1650
|
*/
|
|
1643
1651
|
public async getTokenBalance(tokenId: string): Promise<number> {
|
|
1644
|
-
const utxos = await this.
|
|
1652
|
+
const utxos = (await this.getTokenUtxos(tokenId)).filter(
|
|
1653
|
+
(val) => val.token?.amount
|
|
1654
|
+
);
|
|
1645
1655
|
return sumTokenAmounts(utxos, tokenId);
|
|
1646
1656
|
}
|
|
1647
1657
|
|
|
@@ -1653,7 +1663,9 @@ export class Wallet extends BaseWallet {
|
|
|
1653
1663
|
* @returns {number} non-fungible token balance
|
|
1654
1664
|
*/
|
|
1655
1665
|
public async getNftTokenBalance(tokenId: string): Promise<number> {
|
|
1656
|
-
const utxos = await this.getTokenUtxos(tokenId)
|
|
1666
|
+
const utxos = (await this.getTokenUtxos(tokenId)).filter(
|
|
1667
|
+
(val) => val.token?.commitment !== undefined
|
|
1668
|
+
);
|
|
1657
1669
|
return utxos.length;
|
|
1658
1670
|
}
|
|
1659
1671
|
|
|
@@ -1661,9 +1673,11 @@ export class Wallet extends BaseWallet {
|
|
|
1661
1673
|
* getAllTokenBalances Gets all fungible token balances in this wallet
|
|
1662
1674
|
* @returns {Object} a map [tokenId => balance] for all tokens in this wallet
|
|
1663
1675
|
*/
|
|
1664
|
-
public async getAllTokenBalances(): Promise<
|
|
1676
|
+
public async getAllTokenBalances(): Promise<{ [tokenId: string]: number }> {
|
|
1665
1677
|
const result = {};
|
|
1666
|
-
const utxos = await this.getTokenUtxos()
|
|
1678
|
+
const utxos = (await this.getTokenUtxos()).filter(
|
|
1679
|
+
(val) => val.token?.amount
|
|
1680
|
+
);
|
|
1667
1681
|
for (const utxo of utxos) {
|
|
1668
1682
|
if (!result[utxo.token!.tokenId]) {
|
|
1669
1683
|
result[utxo.token!.tokenId] = 0;
|
|
@@ -1677,9 +1691,13 @@ export class Wallet extends BaseWallet {
|
|
|
1677
1691
|
* getAllNftTokenBalances Gets all non-fungible token (NFT) balances in this wallet
|
|
1678
1692
|
* @returns {Object} a map [tokenId => balance] for all NFTs in this wallet
|
|
1679
1693
|
*/
|
|
1680
|
-
public async getAllNftTokenBalances(): Promise<
|
|
1694
|
+
public async getAllNftTokenBalances(): Promise<{
|
|
1695
|
+
[tokenId: string]: number;
|
|
1696
|
+
}> {
|
|
1681
1697
|
const result = {};
|
|
1682
|
-
const utxos = await this.getTokenUtxos()
|
|
1698
|
+
const utxos = (await this.getTokenUtxos()).filter(
|
|
1699
|
+
(val) => val.token?.commitment !== undefined
|
|
1700
|
+
);
|
|
1683
1701
|
for (const utxo of utxos) {
|
|
1684
1702
|
if (!result[utxo.token!.tokenId]) {
|
|
1685
1703
|
result[utxo.token!.tokenId] = 0;
|