import { VMState } from '@neo-one/client-common';
import { parseChangeReturns } from './converters';
export class SnapshotHandler {
    constructor(dispatcher, snapshot) {
        this.dispatch = dispatcher.dispatch.bind(this);
        this.snapshot = snapshot;
        this.cloneInternal =
            this.snapshot === 'main'
                ? () => this.dispatch({ method: 'snapshot_clone' })
                : () => {
                };
    }
    addBlock(block) {
        const hash = block.hash;
        const buffer = block.serializeWire();
        return this.dispatch({
            method: 'snapshot_blocks_add',
            args: {
                hash,
                block: buffer,
                snapshot: this.snapshot,
            },
        });
    }
    addTransaction(transaction, index, state = VMState.BREAK) {
        const tx = transaction.serializeWire();
        return this.dispatch({
            method: 'snapshot_transactions_add',
            args: {
                tx,
                index,
                state,
                snapshot: this.snapshot,
            },
        });
    }
    deleteTransaction(hash) {
        return this.dispatch({
            method: 'snapshot_transactions_delete',
            args: {
                hash,
                snapshot: this.snapshot,
            },
        });
    }
    changeBlockHashIndex(index, hash) {
        return this.dispatch({
            method: 'snapshot_change_block_hash_index',
            args: {
                index,
                hash,
                snapshot: this.snapshot,
            },
        });
    }
    changeHeaderHashIndex(index, hash) {
        return this.dispatch({
            method: 'snapshot_change_header_hash_index',
            args: {
                index,
                hash,
                snapshot: this.snapshot,
            },
        });
    }
    setPersistingBlock(block) {
        const buffer = block.serializeWire();
        return this.dispatch({
            method: 'snapshot_set_persisting_block',
            args: {
                snapshot: this.snapshot,
                block: buffer,
            },
        });
    }
    hasPersistingBlock() {
        return this.dispatch({
            method: 'snapshot_has_persisting_block',
            args: {
                snapshot: this.snapshot,
            },
        });
    }
    commit(partial) {
        return this.dispatch({
            method: 'snapshot_commit',
            args: {
                partial,
                snapshot: this.snapshot,
            },
        });
    }
    getChangeSet() {
        return parseChangeReturns(this.dispatch({
            method: 'snapshot_get_change_set',
            args: {
                snapshot: this.snapshot,
            },
        }));
    }
    clone() {
        this.cloneInternal();
    }
}

//# sourceMappingURL=SnapshotHandler.js.map
