下午好,
我设置了一个带有 2 台服务器的 bigchaindb 网络。Ubuntu 18.04 和 BigchainDB 2.2.2。
当我尝试提交 CREATE 操作时,我不断收到“ERR_UNHANDLED_REJECTION”。奇怪的是,这只发生在 nodejs 中,在具有完全相同库的 javascript 中它运行良好。
工作 JavaScript 函数:
<script>
const API_PATH = 'https://block.domain.de/api/v1/'
const alice = new BigchainDB.Ed25519Keypair()
const tx = BigchainDB.Transaction.makeCreateTransaction({
token: "TestCoin",
number_tokens: 1000
},{datetime: new Date().toString()},
[BigchainDB.Transaction.makeOutput(BigchainDB.Transaction
.makeEd25519Condition(alice.publicKey), "1000")],
alice.publicKey
)
const txSigned = BigchainDB.Transaction.signTransaction(tx, alice.privateKey)
console.log(txSigned);
let conn = new BigchainDB.Connection(API_PATH)
conn.postTransactionCommit(txSigned)
.then(res => {
const elem = document.getElementById('lastTransaction')
elem.href = API_PATH + 'transactions/' + txSigned.id
elem.innerText = txSigned.id
console.log('Transaction', txSigned.id, 'accepted')
})
失败的NodeJS功能:
const bip39 = require('bip39');
const BigchainDB = require('bigchaindb-driver');
var privateKey = req.query.privateKey;
var publicKey = req.query.publicKey;
var amount = parseInt(req.query.amount);
const alice = new BigchainDB.Ed25519Keypair()
const tx = BigchainDB.Transaction.makeCreateTransaction({
token: "TestCoun",
number_tokens: 1000
},{datetime: new Date().toString()},
[BigchainDB.Transaction.makeOutput(BigchainDB.Transaction
.makeEd25519Condition(alice.publicKey), "1000")],
alice.publicKey
)
const txSigned = BigchainDB.Transaction.signTransaction(tx, alice.privateKey)
let conn = new BigchainDB.Connection(API_PATH)
conn.postTransactionCommit(txSigned)
.then(res => {
res.send("SUCCESS");
})
我尝试了几乎所有代码片段的划分,但我仍然从 NodeJS 收到以下错误:
node:internal/process/promises:245
triggerUncaughtException(err, true /* fromPromise */);
^
[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "#<Object>".] {
code: 'ERR_UNHANDLED_REJECTION'
}
我不明白为什么模拟 cpde 在 nodejs 中抛出错误。
谢谢您的帮助!