all files / src/ operation_call_builder.js

100% Statements 70/70
96.88% Branches 31/32
100% Functions 12/12
100% Lines 14/14
17 statements, 15 branches Ignored     
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                                                                                                           
import {CallBuilder} from "./call_builder";
 
export class OperationCallBuilder extends CallBuilder {
    /**
     * Creates a new {@link OperationCallBuilder} pointed to server defined by serverUrl.
     *
     * Do not create this object directly, use {@link Server#operations}.
     * @see [All Operations](https://www.stellar.org/developers/horizon/reference/operations-all.html)
     * @constructor
     * @extends CallBuilder
     * @param {string} serverUrl Horizon server URL.
     */
    constructor(serverUrl) {
        super(serverUrl);
        this.url.segment('operations');
    }
 
    /**
     * The operation details endpoint provides information on a single operation. The operation ID provided in the id
     * argument specifies which operation to load.
     * @see [Operation Details](https://www.stellar.org/developers/horizon/reference/operations-single.html)
     * @param {number} operationId Operation ID
     * @returns {OperationCallBuilder}
     */
    operation(operationId) {
        this.filter.push(['operations', operationId]);
        return this;
    }
 
    /**
     * This endpoint represents all operations that were included in valid transactions that affected a particular account.
     * @see [Operations for Account](https://www.stellar.org/developers/horizon/reference/operations-for-account.html)
     * @param {string} accountId For example: `GDGQVOKHW4VEJRU2TETD6DBRKEO5ERCNF353LW5WBFW3JJWQ2BRQ6KDD`
     * @returns {OperationCallBuilder}
     */
    forAccount(accountId) {
        this.filter.push(['accounts', accountId, 'operations']);
        return this;
    }
 
    /**
     * This endpoint returns all operations that occurred in a given ledger.
     *
     * @see [Operations for Ledger](https://www.stellar.org/developers/horizon/reference/operations-for-ledger.html)
     * @param {number|string} sequence Ledger sequence
     * @returns {OperationCallBuilder}
     */
    forLedger(sequence) {
        Eif (typeof sequence == 'number') {
            sequence = sequence.toString();
        }
        this.filter.push(['ledgers', sequence, 'operations']);
        return this;
    }
 
    /**
     * This endpoint represents all operations that are part of a given transaction.
     * @see [Operations for Transaction](https://www.stellar.org/developers/horizon/reference/operations-for-transaction.html)
     * @param {string} transactionId Transaction ID
     * @returns {OperationCallBuilder}
     */
    forTransaction(transactionId) {
        this.filter.push(['transactions', transactionId, 'operations']);
        return this;
    }
}