@@ -788,7 +788,8 @@ export default class TransactionSender {
788788 depositOutPoint : OutPoint ,
789789 withdrawingOutPoint : OutPoint ,
790790 fee : string = '0' ,
791- feeRate : string = '0'
791+ feeRate : string = '0' ,
792+ multisigConfig ?: MultisigConfigModel
792793 ) : Promise < Transaction > => {
793794 const DAO_LOCK_PERIOD_EPOCHS = BigInt ( 180 )
794795
@@ -808,7 +809,9 @@ export default class TransactionSender {
808809 throw new TransactionIsNotCommittedYet ( )
809810 }
810811
811- const secpCellDep = await SystemScriptInfo . getInstance ( ) . getSecpCellDep ( )
812+ const cellDep = multisigConfig
813+ ? await SystemScriptInfo . getInstance ( ) . getMultiSignCellDep ( )
814+ : await SystemScriptInfo . getInstance ( ) . getSecpCellDep ( )
812815 const daoCellDep = await SystemScriptInfo . getInstance ( ) . getDaoCellDep ( )
813816
814817 const content = withdrawOutput . daoData
@@ -848,131 +851,27 @@ export default class TransactionSender {
848851
849852 const outputCapacity : bigint = await this . calculateDaoMaximumWithdraw ( depositOutPoint , withdrawBlockHeader . hash )
850853
851- const wallet = WalletService . getInstance ( ) . get ( walletID )
852- const address = await wallet . getNextAddress ( )
853- const blake160 = AddressParser . toBlake160 ( address ! . address )
854-
855- const output : Output = new Output (
856- outputCapacity . toString ( ) ,
857- new Script ( SystemScriptInfo . SECP_CODE_HASH , blake160 , SystemScriptInfo . SECP_HASH_TYPE ) ,
858- undefined ,
859- '0x'
860- )
861-
862- const outputs : Output [ ] = [ output ]
863-
864- const input : Input = new Input (
865- withdrawingOutPoint ,
866- minimalSince . toString ( ) ,
867- withdrawOutput . capacity ,
868- withdrawOutput . lock
869- )
870-
871- const withdrawWitnessArgs : WitnessArgs = new WitnessArgs ( WitnessArgs . EMPTY_LOCK , '0x0000000000000000' )
872- const tx : Transaction = Transaction . fromObject ( {
873- version : '0' ,
874- cellDeps : [ secpCellDep , daoCellDep ] ,
875- headerDeps : [ depositBlockHeader . hash , withdrawBlockHeader . hash ] ,
876- inputs : [ input ] ,
877- outputs,
878- outputsData : outputs . map ( o => o . data || '0x' ) ,
879- witnesses : [ withdrawWitnessArgs ] ,
880- interest : ( BigInt ( outputCapacity ) - depositCapacity ) . toString ( ) ,
881- } )
882- if ( mode . isFeeRateMode ( ) ) {
883- const txSize : number = TransactionSize . tx ( tx )
884- const txFee : bigint = TransactionFee . fee ( txSize , BigInt ( feeRate ) )
885- tx . fee = txFee . toString ( )
886- tx . outputs [ 0 ] . capacity = ( outputCapacity - txFee ) . toString ( )
854+ let output : Output
855+ if ( multisigConfig ) {
856+ const lockScript = Multisig . getMultisigScript (
857+ multisigConfig . blake160s ,
858+ multisigConfig . r ,
859+ multisigConfig . m ,
860+ multisigConfig . n
861+ )
862+ const multisigAddresses = scriptToAddress ( lockScript , NetworksService . getInstance ( ) . isMainnet ( ) )
863+ output = new Output ( outputCapacity . toString ( ) , AddressParser . parse ( multisigAddresses ) , undefined , '0x' )
887864 } else {
888- tx . fee = fee
889- tx . outputs [ 0 ] . capacity = ( outputCapacity - feeInt ) . toString ( )
890- }
891-
892- logger . debug ( 'withdrawFromDao fee:' , tx . fee )
893-
894- return tx
895- }
896-
897- public withdrawFromMultisigDao = async (
898- depositOutPoint : OutPoint ,
899- withdrawingOutPoint : OutPoint ,
900- fee : string = '0' ,
901- feeRate : string = '0' ,
902- multisigConfig : MultisigConfigModel
903- ) : Promise < Transaction > => {
904- const DAO_LOCK_PERIOD_EPOCHS = BigInt ( 180 )
905-
906- const feeInt = BigInt ( fee )
907- const feeRateInt = BigInt ( feeRate )
908- const mode = new FeeMode ( feeRateInt )
909-
910- const currentNetwork = NetworksService . getInstance ( ) . getCurrent ( )
911- const rpcService = new RpcService ( currentNetwork . remote , currentNetwork . type )
912-
913- const withdrawOutput = await CellsService . getLiveCell ( withdrawingOutPoint )
914- if ( ! withdrawOutput ) {
915- throw new CellIsNotYetLive ( )
916- }
917- const prevTx = ( await rpcService . getTransaction ( withdrawingOutPoint . txHash ) ) !
918- if ( ! prevTx . txStatus . isCommitted ( ) ) {
919- throw new TransactionIsNotCommittedYet ( )
920- }
921-
922- const cellDep = await SystemScriptInfo . getInstance ( ) . getMultiSignCellDep ( )
923- const daoCellDep = await SystemScriptInfo . getInstance ( ) . getDaoCellDep ( )
924-
925- const content = withdrawOutput . daoData
926- if ( ! content ) {
927- throw new Error ( `Withdraw output cell is not a dao cell, ${ withdrawOutput . outPoint ?. txHash } ` )
928- }
929- if ( ! withdrawOutput . depositOutPoint ) {
930- throw new Error ( 'DAO has not finish step first withdraw' )
931- }
932- const depositTx = await rpcService . getTransaction ( withdrawOutput . depositOutPoint . txHash )
933- if ( ! depositTx ?. txStatus . blockHash ) {
934- throw new Error ( `Get deposit block hash failed with tx hash ${ withdrawOutput . depositOutPoint . txHash } ` )
935- }
936- const depositBlockHeader = await rpcService . getHeader ( depositTx . txStatus . blockHash )
937- if ( ! depositBlockHeader ) {
938- throw new Error ( `Get Header failed with blockHash ${ depositTx . txStatus . blockHash } ` )
939- }
940- const depositEpoch = this . parseEpoch ( BigInt ( depositBlockHeader . epoch ) )
941- const depositCapacity : bigint = BigInt ( withdrawOutput . capacity )
942-
943- const withdrawBlockHeader = ( await rpcService . getHeader ( prevTx . txStatus . blockHash ! ) ) !
944- const withdrawEpoch = this . parseEpoch ( BigInt ( withdrawBlockHeader . epoch ) )
945-
946- const withdrawFraction = withdrawEpoch . index * depositEpoch . length
947- const depositFraction = depositEpoch . index * withdrawEpoch . length
948- let depositedEpochs = withdrawEpoch . number - depositEpoch . number
949- if ( withdrawFraction > depositFraction ) {
950- depositedEpochs += BigInt ( 1 )
865+ const wallet = WalletService . getInstance ( ) . get ( walletID )
866+ const address = await wallet . getNextAddress ( )
867+ const blake160 = AddressParser . toBlake160 ( address ! . address )
868+ output = new Output (
869+ outputCapacity . toString ( ) ,
870+ new Script ( SystemScriptInfo . SECP_CODE_HASH , blake160 , SystemScriptInfo . SECP_HASH_TYPE ) ,
871+ undefined ,
872+ '0x'
873+ )
951874 }
952- const lockEpochs =
953- ( ( depositedEpochs + ( DAO_LOCK_PERIOD_EPOCHS - BigInt ( 1 ) ) ) / DAO_LOCK_PERIOD_EPOCHS ) * DAO_LOCK_PERIOD_EPOCHS
954- const minimalSinceEpochNumber = depositEpoch . number + lockEpochs
955- const minimalSinceEpochIndex = depositEpoch . index
956- const minimalSinceEpochLength = depositEpoch . length
957-
958- const minimalSince = this . epochSince ( minimalSinceEpochLength , minimalSinceEpochIndex , minimalSinceEpochNumber )
959-
960- const outputCapacity : bigint = await this . calculateDaoMaximumWithdraw ( depositOutPoint , withdrawBlockHeader . hash )
961-
962- const lockScript = Multisig . getMultisigScript (
963- multisigConfig . blake160s ,
964- multisigConfig . r ,
965- multisigConfig . m ,
966- multisigConfig . n
967- )
968- const multisigAddresses = scriptToAddress ( lockScript , NetworksService . getInstance ( ) . isMainnet ( ) )
969-
970- const output : Output = new Output (
971- outputCapacity . toString ( ) ,
972- AddressParser . parse ( multisigAddresses ) ,
973- undefined ,
974- '0x'
975- )
976875
977876 const outputs : Output [ ] = [ output ]
978877
0 commit comments