ไม่สามารถอ่านธุรกรรมจาก Tangle

Aug 25 2020

ในขณะที่ทำตามคำแนะนำ IOTA JavaScriptฉันเปลี่ยนโหนดตัวอย่างเป็นโหนดสุทธิหลัก -https://nodes.thetangle.org:443และได้รับข้อความแสดงข้อผิดพลาดต่อไปนี้ด้านล่าง ฉันจะรับข้อความจากเน็ตหลักได้อย่างไร? ฉันขออภัยหากสิ่งนี้ดูเหมือนเป็นเรื่องเล็กน้อย แต่ฉันก็แค่พยายามทำความเข้าใจทั้งหมดนี้ ขอขอบคุณสำหรับการตอบกลับของคุณล่วงหน้า

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);
  });

ข้อความผิดพลาด:

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)

คำตอบ

1 mihi Aug 25 2020 at 03:40

โมดูล '@ iota / extract-json' เป็นวิธีการเข้ารหัส JSON (ตามความยาวโดยพลการ) ลงในบันเดิล IOTA และถอดรหัสจากที่นั่นอีกครั้ง การถอดรหัสจำเป็นต้องมีการสร้างธุรกรรมในลักษณะเดียวกัน

การทำธุรกรรม IOTA มีวิธีการอื่น ๆ ของการฝังข้อความบางส่วนที่เก่าแก่ที่สุดเป็นหนึ่งที่จะนำพวกเขาใน trytes โดยตรง (เฉพาะพิมพ์ใหญ่ตัวอักษรและ 9 ได้รับอนุญาต) Converter.asciiToTrytesซึ่งเป็นหนึ่งในความเป็นอยู่ต่อไป

ดังที่คุณเห็นในthetangle.orgธุรกรรมของคุณใช้ข้อความธรรมดา (คุณมีตัวเลือกในการแสดง "Text" หรือ "Trytes" แต่เฉพาะ "Text" เท่านั้นที่แสดงข้อความที่มีความหมาย) ในกรณีของข้อความที่เข้ารหัส JSON จะมีตัวเลือก "JSON" ด้วย

ดังนั้นจึงคาดว่าข้อความแสดงข้อผิดพลาด เช่นเดียวกับโปรแกรมแก้ไขรูปภาพของคุณจะแสดงข้อผิดพลาดหากคุณเปิดเอกสาร Word ในนั้น

คุณสามารถรับ trytes ของการทำธุรกรรมของคุณเป็น

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

และข้อความเป็น

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

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