Không thể đọc giao dịch từ Tangle

Aug 25 2020

Trong khi làm theo hướng dẫn IOTA JavaScript , tôi đã thay đổi nút mẫu thành nút mạng chính -https://nodes.thetangle.org:443và nhận được thông báo lỗi sau bên dưới. Làm cách nào để hiển thị thông báo từ mạng chính? Tôi xin lỗi nếu điều này có vẻ hơi thô sơ nhưng tôi chỉ đơn giản là cố gắng hiểu tất cả những điều này. Cảm ơn bạn đã trả lời trước.

const Iota = require('@iota/core');
const Extract = require('@iota/extract-json');

// Connect to a node
const iota = Iota.composeAPI({
  provider: 'https://nodes.iota.org:443'
});

// Define the tail transaction hash of the bundle whose messages you want to read
const tailTransactionHash =
    'UKPUW9NQYXBWXAURISOSCUNFMLSFWKNO9WJOGTEJRCTLJFEIKVBXGUVRAJKZWWMUKDCWLKBJNOYIA9999';

// Get the transaction objects in the bundle
iota.getBundle(tailTransactionHash)
  .then(bundle => {
    // Extract and parse the JSON messages from the transactions' `signatureMessageFragment` fields
    console.log(JSON.parse(Extract.extractJson(bundle)));
  })
  .catch(err => {
    console.error(err);
  });

Thông báo lỗi:

PS C:\IOTA> node Hello_World_Test.js
Error: Invalid JSON encoded message
    at Object.exports.extractJson (C:\IOTA\node_modules\@iota\extract-json\out\extract-json\src\index.js:80:15)
    at C:\IOTA\Hello_World_Test.js:21:36
    at tryCatcher (C:\IOTA\node_modules\bluebird\js\release\util.js:16:23)
    at Promise._settlePromiseFromHandler (C:\IOTA\node_modules\bluebird\js\release\promise.js:547:31)
    at Promise._settlePromise (C:\IOTA\node_modules\bluebird\js\release\promise.js:604:18)
    at Promise._settlePromise0 (C:\IOTA\node_modules\bluebird\js\release\promise.js:649:10)
    at Promise._settlePromises (C:\IOTA\node_modules\bluebird\js\release\promise.js:729:18)
    at _drainQueueStep (C:\IOTA\node_modules\bluebird\js\release\async.js:93:12)
    at _drainQueue (C:\IOTA\node_modules\bluebird\js\release\async.js:86:9)
    at Async._drainQueues (C:\IOTA\node_modules\bluebird\js\release\async.js:102:5)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\IOTA\node_modules\bluebird\js\release\async.js:15:14)
    at processImmediate (internal/timers.js:456:21)

Trả lời

1 mihi Aug 25 2020 at 03:40

Mô-đun '@ iota / extract-json' cung cấp cách mã hóa JSON tùy ý (có độ dài tùy ý) thành một gói IOTA và giải mã lại từ đó. Việc giải mã yêu cầu các giao dịch thực sự phải được xây dựng theo cùng một cách.

Các giao dịch IOTA có các cách khác để nhúng một số văn bản, cách cũ nhất là đưa chúng vào trytes trực tiếp (chỉ cho phép chữ hoa và 9), cách tiếp theo là Converter.asciiToTrytes.

Như bạn có thể thấy trên thetangle.org , giao dịch của bạn sử dụng một tin nhắn văn bản đơn giản (bạn có các tùy chọn để hiển thị "Văn bản" hoặc "Tryte", nhưng chỉ "Văn bản" mới hiển thị văn bản có ý nghĩa). Trong trường hợp thư được mã hóa JSON, cũng sẽ có tùy chọn "JSON".

Do đó, thông báo lỗi được mong đợi. Giống như chương trình chỉnh sửa hình ảnh của bạn sẽ hiển thị lỗi nếu bạn mở tài liệu Word trong đó.

Bạn có thể nhận được trytes của giao dịch của mình như

console.log(bundle[0].signatureMessageFragment);

và tin nhắn văn bản là

const Converter = require('@iota/converter');

Converter.trytesToAscii(bundle[0].signatureMessageFragment.substring(0,2186))