@martiandao/aptos-web3.js
Advanced tools
Comparing version 3.0.4 to 3.0.5
@@ -50,3 +50,3 @@ { | ||
}, | ||
"version": "3.0.4" | ||
"version": "3.0.5" | ||
} |
@@ -9,7 +9,7 @@ import {WalletClient} from "./wallet_client" | ||
test("should be able to create new wallet and airdrop", async () => { | ||
console.log(await apis.getEventStream('de15e8c956964543802ff051c14fe3ccfea70f477e5ebb706f5fee294380bc2d', `0x8e0af08cc9151fd24f6ee1d8125bcdf53607a277b9641f610a0b1dbcd2941e8f::Marketplace::Marketplace`, "list_events")); | ||
// const bob = await apis.createWallet(); | ||
// expect(await apis.getBalance(bob["address key"])).toBe(10); | ||
}); | ||
// test("should be able to create new wallet and airdrop", async () => { | ||
// console.log(await apis.getEventStream('de15e8c956964543802ff051c14fe3ccfea70f477e5ebb706f5fee294380bc2d', `0x8e0af08cc9151fd24f6ee1d8125bcdf53607a277b9641f610a0b1dbcd2941e8f::Marketplace::Marketplace`, "list_events")); | ||
// // const bob = await apis.createWallet(); | ||
// // expect(await apis.getBalance(bob["address key"])).toBe(10); | ||
// }); | ||
@@ -54,24 +54,24 @@ // test("should be able to import wallet", async () => { | ||
// test("should be able to transfer NFT", async () => { | ||
// const alice = await apis.createWallet(); | ||
// // console.log(alice); | ||
// await apis.airdrop(alice['address key'], 10000); | ||
test("should be able to transfer NFT", async () => { | ||
const alice = await apis.createWallet(); | ||
// console.log(alice); | ||
await apis.airdrop(alice['address key'], 10000); | ||
// const bob = await apis.createWallet(); | ||
// // console.log(bob); | ||
// await apis.airdrop(bob['address key'], 10000); | ||
const bob = await apis.createWallet(); | ||
// console.log(bob); | ||
await apis.airdrop(bob['address key'], 10000); | ||
// const collectionName = "AliceCollection"; | ||
// const tokenName = "AliceToken"; | ||
const collectionName = "AliceCollection"; | ||
const tokenName = "AliceToken"; | ||
// await apis.createNFTCollection(alice['code'], collectionName, "Alice's simple collection", "https://aptos.dev"); | ||
// await apis.createNFT(alice['code'], collectionName, tokenName, "Alice's simple token", 1, "https://aptos.dev/img/nyan.jpeg"); | ||
await apis.createNFTCollection(alice['code'], collectionName, "Alice's simple collection", "https://aptos.dev"); | ||
await apis.createNFT(alice['code'], collectionName, tokenName, "Alice's simple token", 1, "https://aptos.dev/img/nyan.jpeg"); | ||
// await apis.offerNFT(alice['code'], bob['address key'], alice['address key'], collectionName, tokenName, 1); | ||
// await apis.claimNFT(bob['code'], alice['address key'], alice['address key'], collectionName, tokenName); | ||
await apis.offerNFT(alice['code'], bob['address key'], alice['address key'], collectionName, tokenName, 1); | ||
await apis.claimNFT(bob['code'], alice['address key'], alice['address key'], collectionName, tokenName); | ||
// const tokens = await apis.getTokens(bob["address key"]); | ||
// expect(tokens[0].name).toBe(tokenName); | ||
// }, | ||
// 30 * 1000); | ||
const tokens = await apis.getTokens(bob["address key"]); | ||
expect(tokens[0].name).toBe(tokenName); | ||
}, | ||
30 * 1000); | ||
@@ -88,20 +88,20 @@ // test("should be able to sign a generic transaction", async () => { | ||
// // test("should be able to rotate an auth key", async function() { | ||
// // const alice = await apis.createWallet(); | ||
// // await apis.airdrop(alice['address key'], 2000); | ||
// test("should be able to rotate an auth key", async function() { | ||
// const alice = await apis.createWallet(); | ||
// await apis.airdrop(alice['address key'], 2000); | ||
// // const bob = await apis.createWallet(); | ||
// const bob = await apis.createWallet(); | ||
// // const newKeys = await apis.getUninitializedAccount() | ||
// const newKeys = await apis.getUninitializedAccount() | ||
// // await apis.rotateAuthKey(alice['code'], newKeys.auth_key.toString()); | ||
// // await apis.transfer(newKeys.code, bob["address key"], 100, alice["address key"]); | ||
// await apis.rotateAuthKey(alice['code'], newKeys.auth_key.toString()); | ||
// await apis.transfer(newKeys.code, bob["address key"], 100, alice["address key"]); | ||
// // const cam = await apis.createWallet(); | ||
// // await apis.airdrop(cam['address key'], 8000); | ||
// const cam = await apis.createWallet(); | ||
// await apis.airdrop(cam['address key'], 8000); | ||
// // await apis.transfer(cam.code, alice["address key"], 5000); | ||
// await apis.transfer(cam.code, alice["address key"], 5000); | ||
// // expect(await apis.getBalance(alice["address key"])).toBeGreaterThan(5000); | ||
// // expect(await apis.getBalance(bob["address key"])).toBe(110); //createwallet() adds 10 coins | ||
// // }); | ||
// expect(await apis.getBalance(alice["address key"])).toBeGreaterThan(5000); | ||
// expect(await apis.getBalance(bob["address key"])).toBe(110); //createwallet() adds 10 coins | ||
// }); |
@@ -303,6 +303,2 @@ import { AptosAccount } from './aptos_account'; | ||
console.log(`${this.aptosClient.nodeUrl}/accounts/${address}/events/${eventHandleStruct}/${fieldName}`); | ||
console.log(response.status); | ||
if(response.status==404) { | ||
@@ -317,6 +313,14 @@ return []; | ||
async getTokenIds(address: string) { | ||
const events = await this.getEventStream(address, "0x1::Token::TokenStore", "deposit_events"); | ||
const depositEvents = await this.getEventStream(address, "0x1::Token::TokenStore", "deposit_events"); | ||
const withdrawEvents = await this.getEventStream(address, "0x1::Token::TokenStore", "withdraw_events"); | ||
function isEventEqual(event1, event2) { | ||
return event1.data.id.creator === event2.data.id.creator && event1.data.id.collectionName === event2.data.id.collectionName && event1.data.id.name === event2.data.id.name; | ||
} | ||
var tokenIds = [] | ||
for (var event of events) { | ||
tokenIds.push(event.data.id) | ||
for (var elem of depositEvents) { | ||
if (!withdrawEvents.some(function(item) { | ||
return isEventEqual(item, elem); | ||
})) { | ||
tokenIds.push(elem.data.id); | ||
} | ||
} | ||
@@ -323,0 +327,0 @@ return tokenIds; |
113628
30
2696