All files / src/api/v1 history.ts

100% Statements 5/5
80% Branches 4/5
100% Functions 5/5
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                                              5x     1x                             2x                       1x               1x              
import {APIClient} from '../client'
 
import {
    Checksum256,
    Checksum256Type,
    Int32,
    Int32Type,
    Name,
    NameType,
    PublicKey,
    PublicKeyType,
    UInt32,
    UInt32Type,
} from '../../chain'
 
import {
    GetActionsResponse,
    GetControlledAccountsResponse,
    GetKeyAccountsResponse,
    GetTransactionResponse,
} from './types'
 
export class HistoryAPI {
    constructor(private client: APIClient) {}
 
    async get_actions(accountName: NameType, pos: Int32Type, offset: Int32Type) {
        return this.client.call({
            path: '/v1/history/get_actions',
            params: {
                account_name: Name.from(accountName),
                pos: Int32.from(pos),
                offset: Int32.from(offset),
            },
            responseType: GetActionsResponse,
        })
    }
 
    async get_transaction(
        id: Checksum256Type,
        options: {blockNumHint?: UInt32Type; excludeTraces?: boolean} = {}
    ) {
        return this.client.call({
            path: '/v1/history/get_transaction',
            params: {
                id: Checksum256.from(id),
                block_num_hint: options.blockNumHint && UInt32.from(options.blockNumHint),
                traces: options.excludeTraces === true ? false : undefined,
            },
            responseType: GetTransactionResponse,
        })
    }
 
    async get_key_accounts(publicKey: PublicKeyType) {
        return this.client.call({
            path: '/v1/history/get_key_accounts',
            params: {public_key: PublicKey.from(publicKey)},
            responseType: GetKeyAccountsResponse,
        })
    }
 
    async get_controlled_accounts(controllingAccount: NameType) {
        return this.client.call({
            path: '/v1/history/get_controlled_accounts',
            params: {controlling_account: Name.from(controllingAccount)},
            responseType: GetControlledAccountsResponse,
        })
    }
}