node.js - Coinbase api - 确认交易的通知
问题描述
海洛斯。
我有一个代码可以让人们使用 coinbase API 进行存款。API 为人员/人员提供地址,并在接收交易时发送 webhook。
有没有办法让它在确认时启用通知?或者代码可以检查确认。
我的代码:
// Create a new document
const newTransaction = new CryptoTransaction({
type: "deposit", // Transaction type
currency, // Crypto currency name
siteValue: exchangedAmount, // Value in site balance (USD)
cryptoValue: cryptoAmount, // Value in crypto currency
address: notification.data.address, // Crypto address
txid: notification.additional_data.hash, // Blockchain transaction id
state: 3, // 1 = pending, 2 = declined, 3 = completed
_user: user.id, // User who made this transaction
});
// Save the document
await newTransaction.save();
// Update user document
await User.updateOne(
{ _id: user.id },
{
$inc: {
wallet: exchangedAmount,
totalDeposited: exchangedAmount,
wagerNeededForWithdraw:
user.wagerNeededForWithdraw < 0
? Math.abs(user.wagerNeededForWithdraw) +
exchangedAmount * 0.5
: exchangedAmount * 0.5, // Add 50% to required wager amount
},
}
);
insertNewWalletTransaction(user.id, exchangedAmount, "Crypto deposit", {
transactionId: newTransaction.id,
});
此代码无需等待 1-blockchain 块即可添加余额
解决方案
推荐阅读
- c# - “System.Object”类型是在未引用的程序集中定义的。您必须添加对程序集“netstandard”的引用
- javascript - PHP 预选下拉菜单
- github - 来自子目录的 Github 页面
- c# - 哪些指令可用于在计算器中执行一系列计算?
- laravel - 如何从laravel购物车中的用户表中分配user_id的值?
- vba - 使用导入工作表列访问匹配表标题
- reactjs - 如何在 React 功能组件中返回不同的页面
- python - 元组的元组
- queue - Apache Pulsar 消息传递语义
- java - Netbeans 中的 Selenium:包 org.openqa.selenium 不存在