import { utils , providers , Signature , constants } from 'ethers' ; import NitroAdjudicatorArtifact from '../../../artifacts/contracts/NitroAdjudicator.sol/NitroAdjudicator.json' ; import { getChannelId , hashState } from '../../' ; import { encodeOutcome } from '../outcome' ; import { getFixedPart , hashAppPart , State } from '../state' ; const NitroAdjudicatorContractInterface = new utils . Interface ( NitroAdjudicatorArtifact . abi ) ; export function concludeAndTransferAllAssetsArgs ( states , signatures , whoSignedWhat ) { if ( states . length === 0 ) { throw new Error ( 'No states provided' ) ; } const { participants } = states [ 0 ] . channel ; if ( participants . length !== signatures . length ) { throw new Error ( `Participants (length:${ participants . length }) and signatures (length:${ signatures . length }) need to be the same length` ) ; } const lastState = states . reduce ( ( s1 , s2 ) => ( s1 . turnNum >= s2 . turnNum ? s1 : s2 ) , states [ 0 ] ) ; const largestTurnNum = lastState . turnNum ; const fixedPart = getFixedPart ( lastState ) ; const appPartHash = hashAppPart ( lastState ) ; const outcomeBytes = encodeOutcome ( lastState . outcome ) ; const numStates = states . length ; return [ largestTurnNum , fixedPart , appPartHash , outcomeBytes , numStates , whoSignedWhat , signatures , ] ; } export function createConcludeAndTransferAllAssetsTransaction ( states , signatures , whoSignedWhat ) { return { data : NitroAdjudicatorContractInterface . encodeFunctionData ( 'concludeAndTransferAllAssets' , concludeAndTransferAllAssetsArgs ( states , signatures , whoSignedWhat ) ) , } ; } function transferAllAssetsArgs ( state , overrideStateHash = false ) { const channelId = getChannelId ( state . channel ) ; const outcomeBytes = encodeOutcome ( state . outcome ) ; const stateHash = overrideStateHash ? constants . HashZero : hashState ( state ) ; return [ channelId , outcomeBytes , stateHash ] ; } export function createTransferAllAssetsTransaction ( state , overrideStateHash = false ) { return { data : NitroAdjudicatorContractInterface . encodeFunctionData ( 'transferAllAssets' , transferAllAssetsArgs ( state , overrideStateHash ) ) , } ; }