function createWallet(network, walletToken, deviceToken) {
return new Promise((resolve, reject) => {
findWalletByWalletToken(network, walletToken)
.then((docs) => {
if (docs.length !== 0) {
for (var i in docs) {
if (docs[i].curDeviceToken == deviceToken || docs[i].walletToken.indexOf(walletToken) !== -1){
reject(new Error("walletToken already exists"));
return
}
}
}
console.log(docs)
})
.catch((err) => {
console.log(err);
})
findDeviceByDeviceToken(network, deviceToken)
.then((docs) => {
resolve(docs);
})
})
.then((docs) => {
// Adds a wallet
}
The log looks like this
Docs in WalletTokenSearch[object Object],[object Object]
Docs in WalletTokenSearch[object Object],[object Object]
Docs in WalletTokenSearch[object Object],[object Object]
Docs in WalletTokenSearch[object Object],[object Object]
Docs in WalletTokenSearch[object Object],[object Object]
Docs in WalletTokenSearch[object Object],[object Object]
Docs in WalletTokenSearch[object Object],[object Object]
[Hail][DB] Inserted new wallet
Docs in WalletTokenSearch[object Object],[object Object]
The Docs in WalletTokenSearch[object Object],[object Object]
is a print statement in findWalletByWalletToken
The problem is that I’ll hit the endpoint multiple times and every now and then the same input will pass through the code and get added to the db creating a duplicate… You could do this over and over again and add thousands of duplicates this way