Skip to content

Commit

Permalink
fix/transaction: throw a meaningful error when the user tries to `dec…
Browse files Browse the repository at this point in the history
…ode` an array + update README
  • Loading branch information
rosmcmahon committed Apr 17, 2023
1 parent 099ca77 commit 55a212a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
10 changes: 10 additions & 0 deletions src/common/lib/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit 55a212a

Please sign in to comment.