Skip to content

Commit

Permalink
add extra data decoding (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
n0cte authored Jun 16, 2021
1 parent d0ad6e1 commit 2cad231
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,20 @@ export const decodeReceiptData = (data: string) => { // eslint-disable-line
gasUsed: decoded[1].toString('hex'),
data: decoded[2].toString('hex'),
}
}

export const decodeExtra = (data: string) => { // eslint-disable-line
const extra = Buffer.from(data.slice(0, 64), 'hex')
let right = extra.length - 1
for (; right >= 0 && extra[right] == 0; right--) {} // eslint-disable-line
if (right % 2 != 0){
right++
}
const tmp: any = rlp.decode(extra.slice(0, right+1)) // eslint-disable-line
return tmp.reduce(function(str, value, i){
if (i === 0) {
return value.toString('hex')
}
return `${str}/${value.toString('utf-8')}`
}, '');
}

0 comments on commit 2cad231

Please sign in to comment.