From 55a212a2df356b147f9cbe003f29d2341e794619 Mon Sep 17 00:00:00 2001 From: Ros McMahon Date: Mon, 17 Apr 2023 19:46:54 +0700 Subject: [PATCH] fix/transaction: throw a meaningful error when the user tries to `decode` an array + update README --- README.md | 2 +- src/common/lib/transaction.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d03eee33..e91637fb 100644 --- a/README.md +++ b/README.md @@ -536,7 +536,7 @@ arweave.transactions.getData('bNbA3TEQVL60xlgCcqdz4ZPHFZ711cZ3hmkpGttDt_U', {dec ```js const transaction = arweave.transactions.get('bNbA3TEQVL60xlgCcqdz4ZPHFZ711cZ3hmkpGttDt_U').then(transaction => { - transaction.get('tags').forEach(tag => { + transaction['tags'].forEach(tag => { let key = tag.get('name', {decode: true, string: true}); let value = tag.get('value', {decode: true, string: true}); console.log(`${key} : ${value}`); diff --git a/src/common/lib/transaction.ts b/src/common/lib/transaction.ts index c2135e4d..a6ad590f 100644 --- a/src/common/lib/transaction.ts +++ b/src/common/lib/transaction.ts @@ -38,6 +38,16 @@ class BaseObject { return ArweaveUtils.bufferTob64Url(this[field]); } + if (this[field] instanceof Array) { + if(options?.decode !== undefined || options?.string !== undefined) { + if(field === "tags") { + console.warn(`Did you mean to use 'transaction["tags"]' ?`); + } + throw new Error(`Cannot decode or stringify an array.`); + } + return this[field]; + } + if (options && options.decode == true) { if (options && options.string) { return ArweaveUtils.b64UrlToString(this[field]);