import * as Knex from 'knex' ; import { addAddressCheck , addBytes32CheckOld , addUint48Check , dropConstraint } from '../utils' ; export const channels = 'channels' ; const signingWallets = 'signing_wallets' ; export async function addByteContraints ( knex ) { await addBytes32CheckOld ( knex , signingWallets , 'private_key' ) ; await addAddressCheck ( knex , signingWallets , 'address' ) ; await addBytes32CheckOld ( knex , channels , 'channel_id' ) ; await addAddressCheck ( knex , channels , 'app_definition' ) ; await addAddressCheck ( knex , channels , 'signing_address' ) ; } export async function dropByteConstraints ( knex ) { await dropConstraint ( knex , signingWallets , 'private_key_is_bytes32' ) ; await dropConstraint ( knex , channels , 'channel_id_is_bytes32' ) ; } export async function up ( knex ) { await knex . schema . createTable ( signingWallets , function ( table ) { table . increments ( 'id' ) ; table . string ( 'private_key' ) . notNullable ( ) . unique ( ) ; table . string ( 'address' ) . notNullable ( ) . unique ( ) ; } ) ; await knex . schema . createTable ( channels , function ( table ) { table . increments ( 'id' ) ; table . string ( 'channel_id' ) . notNullable ( ) . unique ( ) ; table . string ( 'signing_address' ) . notNullable ( ) ; table . foreign ( 'signing_address' ) . references ( 'signing_wallets.address' ) ; table . string ( 'chain_id' ) . notNullable ( ) ; table . integer ( 'channel_nonce' ) . notNullable ( ) ; table . string ( 'app_definition' ) . notNullable ( ) ; table . integer ( 'challenge_duration' ) . notNullable ( ) ; table . jsonb ( 'vars' ) . notNullable ( ) ; table . jsonb ( 'participants' ) . notNullable ( ) ; } ) ; await addByteContraints ( knex ) ; await addUint48Check ( knex , channels , 'channel_nonce' ) ; await addUint48Check ( knex , channels , 'challenge_duration' ) ; } export async function down ( knex ) { await knex . schema . dropTable ( channels ) ; await knex . schema . dropTable ( signingWallets ) ; }