import PWCore , { CKBModel , CellDep , Cell } from '..' ; import { SerializeRawTransaction } from '@ckb-lumos/types/lib/core' ; import { validators , normalizers , Reader , transformers } from 'ckb-js-toolkit' ; import { CellInput } from './cell-input' ; import { Blake2bHasher } from '../hashers' ; export class RawTransaction implements CKBModel { public inputs : CellInput [ ] ; public outputsData : string [ ] ; constructor ( public inputCells , public outputs , public cellDeps = [ PWCore . config . defaultLock . cellDep , PWCore . config . pwLock . cellDep , ] , public headerDeps = [ ] , public readonly version = '0x0' ) { this . inputs = inputCells . map ( ( i ) => i . toCellInput ( ) ) ; this . outputsData = this . outputs . map ( ( o ) => o . getHexData ( ) ) ; } sameWith ( raw ) { validators . ValidateTransaction ( transformers . TransformTransaction ( raw ) ) ; return raw . toHash ( ) === this . toHash ( ) ; } toHash ( ) { const rawTx = transformers . TransformRawTransaction ( this ) ; const hasher = new Blake2bHasher ( ) ; return hasher . hash ( new Reader ( SerializeRawTransaction ( normalizers . NormalizeRawTransaction ( rawTx ) ) ) ) . serializeJson ( ) ; } validate ( ) { validators . ValidateRawTransaction ( transformers . TransformRawTransaction ( this ) ) ; return true ; } serializeJson ( ) { return { version : this . version , cell_deps : this . cellDeps , header_deps : this . headerDeps , inputs : this . inputs , outputs : this . outputs , outputs_data : this . outputsData , } ; } }