@@ -549,18 +549,13 @@ function handleCommit(ChainSQL, object, resolve, reject) {
549549 delete cache [ i ] . TableName ;
550550 delete cache [ i ] . confidential ;
551551 payment . Statements . push ( cache [ i ] ) ;
552- } ;
552+ }
553553
554554 //clear transactin status
555555 ChainSQL . transaction = false ;
556556 ChainSQL . cache = [ ] ;
557557
558558 getTxJson ( ChainSQL , payment ) . then ( function ( data ) {
559- if ( data . status == 'error' ) {
560- ChainSQL . transaction = false ;
561- throw new Error ( 'getTxJson error' ) ;
562- }
563-
564559 var payment = data . tx_json ;
565560 payment . Statements = convertStringToHex ( JSON . stringify ( payment . Statements ) ) ;
566561 ChainSQL . api . prepareTx ( payment ) . then ( function ( data ) {
@@ -573,6 +568,12 @@ function handleCommit(ChainSQL, object, resolve, reject) {
573568 } ) . catch ( function ( error ) {
574569 cb ( error , null ) ;
575570 } ) ;
571+ } ) . catch ( function ( error ) {
572+ ChainSQL . transaction = false ;
573+ if ( error . error_message )
574+ throw new Error ( error . error_message ) ;
575+ else
576+ throw new Error ( 'getTxJson error' ) ;
576577 } ) ;
577578 } ) ;
578579}
@@ -718,16 +719,15 @@ function prepareTable(ChainSQL, payment, object, resolve, reject) {
718719 ChainSQL . api . prepareTable ( payment ) . then ( function ( tx_json ) {
719720 // console.log(tx_json);
720721 getTxJson ( ChainSQL , JSON . parse ( tx_json . txJSON ) ) . then ( function ( data ) {
721- if ( data . status == 'error' ) {
722- if ( data . error_message )
723- errFunc ( new Error ( data . error_message ) ) ;
724- else
725- errFunc ( new Error ( 'getTxJson error' ) ) ;
726- }
727722 data . tx_json . Fee = util . calcFee ( data . tx_json ) ;
728723 var payment = data . tx_json ;
729724 let signedRet = ChainSQL . api . sign ( JSON . stringify ( data . tx_json ) , ChainSQL . connect . secret ) ;
730725 handleSignedTx ( ChainSQL , signedRet , object , resolve , reject ) ;
726+ } ) . catch ( function ( error ) {
727+ if ( error . error_message )
728+ errFunc ( new Error ( error . error_message ) ) ;
729+ else
730+ errFunc ( new Error ( 'getTxJson error' ) ) ;
731731 } ) ;
732732 } ) . catch ( function ( error ) {
733733 errFunc ( error ) ;
@@ -794,53 +794,42 @@ ChainsqlAPI.prototype.getAccountTables = function(address, bGetDetailInfo=false)
794794 account : address ,
795795 detail : bGetDetailInfo
796796 } ) . then ( function ( data ) {
797- dealWithRet ( data , resolve , reject ) ;
797+ resolve ( data ) ;
798798 } ) . catch ( function ( err ) {
799799 reject ( err ) ;
800- } )
801- } )
802- }
800+ } ) ;
801+ } ) ;
802+ } ;
803803
804804ChainsqlAPI . prototype . getTableAuth = function ( owner , tableName , accounts ) {
805805 var connection = this . api ? this . api . connection : this . connect . api . connection ;
806806 var req = {
807807 command : 'table_auth' ,
808808 owner : owner ,
809809 tablename :tableName
810- }
810+ } ;
811811 if ( accounts && accounts . length > 0 ) {
812812 req . accounts = accounts ;
813813 }
814814 return new Promise ( function ( resolve , reject ) {
815815 connection . request ( req ) . then ( function ( data ) {
816- dealWithRet ( data , resolve , reject ) ;
816+ resolve ( data ) ;
817817 } ) . catch ( function ( err ) {
818818 reject ( err ) ;
819- } )
820- } )
821- }
819+ } ) ;
820+ } ) ;
821+ } ;
822822
823- function dealWithRet ( data , resolve , reject ) {
824- if ( data . status == 'success' ) {
825- resolve ( data ) ;
826- } else {
827- reject ( data ) ;
828- }
829- }
830823ChainsqlAPI . prototype . getTableNameInDB = function ( owner , tableName ) {
831824 var that = this ;
832825 return new Promise ( function ( resolve , reject ) {
833826 util . getTableName ( that , owner , tableName ) . then ( function ( data ) {
834- if ( data . status == 'success' ) {
835- resolve ( data . nameInDB ) ;
836- } else {
837- reject ( data ) ;
838- }
827+ resolve ( data . nameInDB ) ;
839828 } ) . catch ( function ( err ) {
840829 reject ( err ) ;
841- } )
842- } )
843- }
830+ } ) ;
831+ } ) ;
832+ } ;
844833
845834ChainsqlAPI . prototype . getBySqlAdmin = function ( sql ) {
846835 var connection = this . api ? this . api . connection : this . connect . api . connection ;
@@ -849,19 +838,19 @@ ChainsqlAPI.prototype.getBySqlAdmin = function(sql){
849838 command : 'r_get_sql_admin' ,
850839 sql :sql
851840 } ) . then ( function ( data ) {
852- dealWithRet ( data , resolve , reject ) ;
841+ resolve ( data ) ;
853842 } ) . catch ( function ( err ) {
854843 reject ( err ) ;
855- } )
856- } )
857- }
844+ } ) ;
845+ } ) ;
846+ } ;
858847
859848ChainsqlAPI . prototype . getBySqlUser = function ( sql ) {
860849 var connect = this . connect ;
861850 var json = {
862851 Account :connect . address ,
863852 Sql :sql
864- }
853+ } ;
865854 return new Promise ( function ( resolve , reject ) {
866855 util . getValidatedLedgerIndex ( connect ) . then ( function ( ledgerVersion ) {
867856 json . LedgerIndex = ledgerVersion ;
@@ -875,14 +864,12 @@ ChainsqlAPI.prototype.getBySqlUser = function(sql){
875864 tx_json :json
876865 } )
877866 } ) . then ( function ( data ) {
878- dealWithRet ( data , resolve , reject ) ;
867+ resolve ( data ) ;
879868 } ) . catch ( function ( err ) {
880869 reject ( err ) ;
881870 } ) ;
882- } )
883-
884-
885- }
871+ } ) ;
872+ } ;
886873
887874ChainsqlAPI . prototype . submit = function ( cb ) {
888875 var that = this ;
0 commit comments