Home Reference Source Test
public class | source

SimbaBase

Direct Subclass:

Simbachain

Constructor Summary

Public Constructor
public

constructor(endpoint: string, wallet: Wallet)

Base class for libsimba API Interaction implementations

Member Summary

Public Members
public

apiKey: *

public
public
public

metadata: {}

public

wallet: *

Method Summary

Public Methods
public abstract
public abstract

callMethod(method: string, parameters: Object): Promise

public abstract

callMethodWithFile(method: string, parameters: Object, files: Array<Blob|File>): Promise<Object>

public abstract
public abstract
public abstract

getBundleForTransaction(transactionIdOrHash: string, stream: boolean): Promise<ReadableStream|Blob>

public abstract
public abstract

getFileFromBundleByNameForTransaction(transactionIdOrHash: string, fileName: string, stream: boolean): Promise<ReadableStream|Blob>

public abstract

getFileFromBundleForTransaction(transactionIdOrHash: string, fileIdx: number, stream: boolean): Promise<ReadableStream|Blob>

public abstract

getMethodTransactions(method: string, parameters: Object)

public abstract

getTransaction(transactionIdOrHash: string): Promise<Object>

public abstract
public abstract
public abstract
public abstract
public

setApiKey(apiKey: string)

Set the API Key to authenticate calls

public

setManagementKey(managementKey: string)

Set the API Key to authenticate management calls

public

setWallet(wallet: Wallet)

Set the wallet

public

waitForSuccessOrError(txnId: string, pollInterval: number): *

Returns an object with 'future' and 'cancel' keys.

Private Methods
private

apiAuthHeaders(): {APIKEY: *, "Content-Type": string}

private abstract
private abstract
private

managementAuthHeaders(): {APIKEY: *, "Content-Type": string}

private
private

validateCall(methodName: string, parameters: Object, files: Array): boolean

private

validateGetCall(methodName: string, parameters: Object): boolean

Public Constructors

public constructor(endpoint: string, wallet: Wallet) source

Base class for libsimba API Interaction implementations

Params:

NameTypeAttributeDescription
endpoint string

The endpoint of the API

wallet Wallet
  • optional

an optional Wallet instance

Public Members

public apiKey: * source

public endpoint: string source

public managementKey: * source

public metadata: {} source

public wallet: * source

Public Methods

public abstract addFunds(): Promise<Object> source

Return:

Promise<Object>

details of the txn

public abstract callMethod(method: string, parameters: Object): Promise source

Params:

NameTypeAttributeDescription
method string

the method to call

parameters Object

the parameters for the method

Return:

Promise

a promise resolving with the transaction details

public abstract callMethodWithFile(method: string, parameters: Object, files: Array<Blob|File>): Promise<Object> source

Params:

NameTypeAttributeDescription
method string

the method to call

parameters Object

the parameters for the method

files Array<Blob|File>

the files

Return:

Promise<Object>

a promise resolving with the transaction details

public abstract checkTransactionStatus(txnId: string): Object source

Params:

NameTypeAttributeDescription
txnId string

a transaction ID

Return:

Object

an object with status details

public abstract getBalance(): Promise<Object> source

Return:

Promise<Object>

the balance

public abstract getBundleForTransaction(transactionIdOrHash: string, stream: boolean): Promise<ReadableStream|Blob> source

Params:

NameTypeAttributeDescription
transactionIdOrHash string

Either a transaction ID or a transaction hash

stream boolean

If true, returns a ReadableStream, otherwise returns a Blob

Return:

Promise<ReadableStream|Blob>

The bundle

public abstract getBundleMetadataForTransaction(transactionIdOrHash: string): Promise<Object> source

Params:

NameTypeAttributeDescription
transactionIdOrHash string

Either a transaction ID or a transaction hash

Return:

Promise<Object>

The bundle metadata

public abstract getFileFromBundleByNameForTransaction(transactionIdOrHash: string, fileName: string, stream: boolean): Promise<ReadableStream|Blob> source

Params:

NameTypeAttributeDescription
transactionIdOrHash string

Either a transaction ID or a transaction hash

fileName string

The name of the file in the bundle metadata

stream boolean

If true, returns a ReadableStream, otherwise returns a Blob

Return:

Promise<ReadableStream|Blob>

The file

public abstract getFileFromBundleForTransaction(transactionIdOrHash: string, fileIdx: number, stream: boolean): Promise<ReadableStream|Blob> source

Params:

NameTypeAttributeDescription
transactionIdOrHash string

Either a transaction ID or a transaction hash

fileIdx number

The index of the file in the bundle metadata

stream boolean

If true, returns a ReadableStream, otherwise returns a Blob

Return:

Promise<ReadableStream|Blob>

The file

public abstract getMethodTransactions(method: string, parameters: Object) source

Params:

NameTypeAttributeDescription
method string

The method

parameters Object

The query parameters

public abstract getTransaction(transactionIdOrHash: string): Promise<Object> source

Params:

NameTypeAttributeDescription
transactionIdOrHash string

Either a transaction ID or a transaction hash

Return:

Promise<Object>

The transaction

public abstract getTransactionStatus(txnId: string): Promise<Object> source

Params:

NameTypeAttributeDescription
txnId string

the transaction ID

Return:

Promise<Object>

a promise resolving with the transaction details

public abstract getTransactions(parameters: Object): Promise<PagedResponse> source

Params:

NameTypeAttributeDescription
parameters Object

The query parameters

Return:

Promise<PagedResponse>

A response wrapped in a PagedResponse helper

public abstract initialize() source

public abstract async sendTransactionRequest(url: URL): Promise<PagedResponse> source

Params:

NameTypeAttributeDescription
url URL

The URL

Return:

Promise<PagedResponse>

A response wrapped in a PagedResponse helper

public setApiKey(apiKey: string) source

Set the API Key to authenticate calls

Params:

NameTypeAttributeDescription
apiKey string

the API Key

public setManagementKey(managementKey: string) source

Set the API Key to authenticate management calls

Params:

NameTypeAttributeDescription
managementKey string

the management API Key

public setWallet(wallet: Wallet) source

Set the wallet

Params:

NameTypeAttributeDescription
wallet Wallet

the wallet

public waitForSuccessOrError(txnId: string, pollInterval: number): * source

Returns an object with 'future' and 'cancel' keys. future is the promise to listen on for the response or an error. cancel is a function - call it to cancel the polling.

Params:

NameTypeAttributeDescription
txnId string

the transaction ID

pollInterval number
  • optional
  • default: 5000

the interval in ms for polling

Return:

*

Private Methods

private apiAuthHeaders(): {APIKEY: *, "Content-Type": string} source

Return:

{APIKEY: *, "Content-Type": string}

private abstract checkTransactionDone(txn: Object): boolean source

Params:

NameTypeAttributeDescription
txn Object

the transaction object

Return:

boolean

is the transaction complete

private abstract checkTransactionStatusFromObject(txn: Object): Object source

Params:

NameTypeAttributeDescription
txn Object

a transaction object

Return:

Object

an object with status details

private managementAuthHeaders(): {APIKEY: *, "Content-Type": string} source

Return:

{APIKEY: *, "Content-Type": string}

private validateAnyGetCall(): boolean source

Return:

boolean

Throw:

MissingMetadataException

App Metadata not yet retrieved

BadMetadataException

App Metadata doesn't have methods

private validateCall(methodName: string, parameters: Object, files: Array): boolean source

Params:

NameTypeAttributeDescription
methodName string

the methods name

parameters Object

the parameters for the method call

files Array
  • optional

Optional array of files

Return:

boolean

Throw:

MissingMetadataException

App Metadata not yet retrieved

BadMetadataException

App Metadata doesn't have methods

MethodCallValidationMetadataException

Method call fails validation

private validateGetCall(methodName: string, parameters: Object): boolean source

Params:

NameTypeAttributeDescription
methodName string

the methods name

parameters Object

the parameters for the query

Return:

boolean

Throw:

MissingMetadataException

App Metadata not yet retrieved

BadMetadataException

App Metadata doesn't have methods

MethodCallValidationMetadataException

Method call fails validation