Skip to content

Commit

Permalink
Add shorthand reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaptic committed Jul 28, 2023
1 parent c40e8db commit 81e73fa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/sorobandata_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export class SorobanDataBuilder {
constructor(sorobanData) {
let data;

if (typeof sorobanData === 'string') {
data = xdr.SorobanTransactionData.fromXDR(sorobanData, 'base64');
if (typeof sorobanData === 'string' || ArrayBuffer.isView(sorobanData)) {
data = SorobanDataBuilder.fromXDR(sorobanData);
} else if (!sorobanData) {
data = new xdr.SorobanTransactionData({
resources: new xdr.SorobanResources({
Expand All @@ -56,6 +56,18 @@ export class SorobanDataBuilder {
this._data = data;
}

/**
* Decodes and builds a {@link xdr.SorobanTransactionData} instance.
* @param {Uint8Array|Buffer|string} data raw input to decode
* @returns {xdr.SorobanTransactionData}
*/
static fromXDR(data) {
return xdr.SorobanTransactionData.fromXDR(
data,
typeof data === 'string' ? 'base64' : 'raw'
);
}

/**
* Sets the "refundable" fee portion of the Soroban data.
* @param {number | bigint | string} fee the refundable fee to set (int64)
Expand Down

0 comments on commit 81e73fa

Please sign in to comment.