import { Objective , ChannelStoredData , DomainBudget , StateVariables } from '@statechannels/wallet-core' ; import { filter , map } from 'rxjs/operators' ; import { Store } from './store' ; import { ChannelStoreEntry } from './channel-store-entry' ; export { Store } from './store' ; export function supportedStateFeed ( store , channelId ) { return store . channelUpdatedFeed ( channelId ) . pipe ( filter ( e => ! ! e . supported ) , map ( e => ( { state : { ... e . channelConstants , ... ( e . supported as StateVariables ) } } ) ) ) ; } export enum Errors { duplicateTurnNums = 'multiple states with same turn number' , notSorted = 'states not sorted' , multipleSignedStates = 'Store signed multiple states for a single turn' , staleState = 'Attempting to sign a stale state' , channelMissing = 'No channel found with id.' , channelFunded = 'Channel already funded.' , channelLocked = 'Channel is locked' , noBudget = 'No budget exists for domain. ' , noAssetBudget = "This domain's budget does contain this asset" , channelNotInBudget = "This domain's budget does not reference this channel" , noDomainForChannel = 'No domain defined for channel' , domainExistsOnChannel = 'Channel already has a domain.' , budgetAlreadyExists = 'There already exists a budget for this domain' , budgetInsufficient = 'Budget insufficient to reserve funds' , amountUnauthorized = 'Amount unauthorized in current budget' , cannotFindDestination = 'Cannot find destination for participant' , cannotFindPrivateKey = 'Private key missing for your address' , notInChannel = 'Attempting to initialize  channel as a non-participant' , noLedger = 'No ledger exists with peer' , amountNotFound = 'Cannot find allocation entry with destination' , invalidNonce = 'Invalid nonce' , invalidTransition = 'Invalid transition' , invalidAppData = 'Invalid app data' , emittingDuringTransaction = 'Attempting to emit event during transaction' , notMyTurn = "Cannot update channel unless it's your turn" , objectiveAlreadyExists = 'Objective for a channel id already exists' } export interface DBBackend { initialize ( cleanSlate , name ) : Promise < any > ; privateKeys ( ) : Promise < Record < string , string | undefined > > ; ledgers ( ) : Promise < Record < string , string | undefined > > ; nonces ( ) : Promise < Record < string , number | undefined > > ; objectives ( ) : Promise < Objective [ ] > ; channels ( ) : Promise < Record < string , ChannelStoreEntry | undefined > > ; setDestinationAddress ( destinationAddress ) : Promise < string > ; getDestinationAddress ( ) : Promise < string | undefined > ; setPrivateKey ( key , value ) : Promise < string > ; getPrivateKey ( key ) : Promise < string | undefined > ; setChannel ( key , value ) : Promise < ChannelStoredData > ; getChannel ( key ) : Promise < ChannelStoreEntry | undefined > ; getBudget ( key ) : Promise < DomainBudget | undefined > ; setBudget ( key , budget ) : Promise < DomainBudget > ; deleteBudget ( key ) : Promise < void > ; setLedger ( key , value ) : Promise < string > ; getLedger ( key ) : Promise < string | undefined > ; setNonce ( key , value ) : Promise < number > ; getNonce ( key ) : Promise < number | undefined > ; setObjective ( key , value ) : Promise < Objective > ; getObjective ( key ) : Promise < Objective | undefined > ; param mode param stores param cb returns transaction < T , S extends ObjectStores > ( mode , stores , cb ) : Promise < T > ; transactionOngoing : boolean ; } export type Transaction = { abort ( ) : void ; } ; export type TXMode = 'readonly' | 'readwrite' ; export const enum ObjectStores { channels = 'channels' , objectives = 'objectives' , nonces = 'nonces' , privateKeys = 'privateKeys' , destinationAddress = 'destinationAddress' , ledgers = 'ledgers' , budgets = 'budgets' } declare global { interface Window { ethereum : any ; } }