@@ -224,9 +224,9 @@ ChainsqlAPI.prototype.escrowCancel = function (sOwnerAddr, nCreateEscrowSeq) {
224224 return ripple . escrowCancel ( sOwnerAddr , nCreateEscrowSeq ) ;
225225}
226226
227- ChainsqlAPI . prototype . createTable = function ( name , raw , opt ) {
227+ ChainsqlAPI . prototype . createTable = function ( name , raw , inputOpt ) {
228228 validate . create ( name , raw ) ;
229- var opt = opt ? opt : { } ;
229+ var opt = inputOpt ? inputOpt : { } ;
230230 let that = this ;
231231 var confidential = false ;
232232 if ( opt . confidential ) {
@@ -264,8 +264,9 @@ ChainsqlAPI.prototype.createTable = function (name, raw, opt) {
264264 payment . raw = crypto . aesEncrypt ( secret , payment . raw ) . toUpperCase ( ) ;
265265 payment . token = token . toUpperCase ( ) ;
266266 } else {
267- payment . raw = convertStringToHex ( payment . raw )
268- } ;
267+ payment . raw = convertStringToHex ( payment . raw ) ;
268+ }
269+
269270 if ( payment . operationRule ) {
270271 payment . operationRule = convertStringToHex ( payment . operationRule ) ;
271272 }
@@ -613,8 +614,17 @@ ChainsqlAPI.prototype.getLedgerVersion = function (cb) {
613614
614615function handleSignedTx ( ChainSQL , signed , object , resolve , reject ) {
615616 var isFunction = false ;
616- if ( ( typeof object ) == 'function' )
617- isFunction = true ;
617+ let expectOpt = { expect :"send_success" } ;
618+ let cbCheckRet = util . checkCbOpt ( object ) ;
619+ if ( cbCheckRet . status === "success" ) {
620+ if ( cbCheckRet . type === "function" ) {
621+ isFunction = cbCheckRet . isFunction ;
622+ } else {
623+ expectOpt . expect = cbCheckRet . expect ;
624+ }
625+ } else {
626+ return reject ( cbCheckRet . errMsg ) ;
627+ }
618628
619629 var errFunc = function ( error ) {
620630 if ( isFunction ) {
@@ -636,52 +646,56 @@ function handleSignedTx(ChainSQL, signed, object, resolve, reject) {
636646 } else {
637647 resolve ( data ) ;
638648 }
639- }
649+ } ;
640650 // subscribe event
641- ChainSQL . event . subscribeTx ( signed . id , isFunction ? object : function ( err , data ) {
642- if ( err ) {
643- errFunc ( err ) ;
644- } else {
645- // success
646- if ( object != undefined
647- && object . expect == data . status
648- && data . type === 'singleTransaction' ) {
649- sucFunc ( {
650- status : object . expect ,
651- tx_hash : signed . id
652- } ) ;
653- }
654-
655- // failure
656- if ( util . checkSubError ( data ) ) {
657- var error = {
658- status : data . status ,
659- tx_hash : signed . id
651+ if ( expectOpt . expect !== "send_success" ) {
652+ ChainSQL . event . subscribeTx ( signed . id , isFunction ? object : function ( err , data ) {
653+ if ( err ) {
654+ errFunc ( err ) ;
655+ } else {
656+ // success
657+ if ( expectOpt . expect === data . status
658+ && data . type === 'singleTransaction' ) {
659+ sucFunc ( {
660+ status : expectOpt . expect ,
661+ tx_hash : signed . id
662+ } ) ;
660663 }
661- if ( data . hasOwnProperty ( "error_message" ) ) {
662- error . error_message = data . error_message ;
664+
665+ // failure
666+ if ( util . checkSubError ( data ) ) {
667+ var error = {
668+ status : data . status ,
669+ tx_hash : signed . id
670+ } ;
671+ if ( data . hasOwnProperty ( "error_message" ) ) {
672+ error . error_message = data . error_message ;
673+ }
674+ errFunc ( error ) ;
663675 }
664- errFunc ( error ) ;
665676 }
666- }
667- } ) . then ( function ( data ) {
668- // subscribeTx success
669- } ) . catch ( function ( error ) {
670- // subscribeTx failure
671- errFunc ( 'subscribeTx exception.' + error ) ;
672- } ) ;
677+ } ) . then ( function ( data ) {
678+ // subscribeTx success
679+ } ) . catch ( function ( error ) {
680+ // subscribeTx failure
681+ errFunc ( 'subscribeTx exception.' + error ) ;
682+ } ) ;
683+ }
684+
673685
674686 // submit transaction
675687 ChainSQL . api . submit ( signed . signedTransaction ) . then ( function ( result ) {
676688 //console.log('submit ', JSON.stringify(result));
677689 if ( result . resultCode != 'tesSUCCESS' ) {
678- ChainSQL . event . unsubscribeTx ( signed . id ) ;
690+ if ( expectOpt . expect !== "send_success" ) {
691+ ChainSQL . event . unsubscribeTx ( signed . id ) ;
692+ }
679693 //return error message
680694 errFunc ( result ) ;
681695 } else {
682696 // submit successfully
683- if ( ( isFunction == false && object != undefined && object . expect == 'send_success' ) || object == undefined ) {
684- ChainSQL . event . unsubscribeTx ( signed . id ) ;
697+ if ( expectOpt . expect === "send_success" ) {
698+ // ChainSQL.event.unsubscribeTx(signed.id);
685699 sucFunc ( {
686700 status : 'send_success' ,
687701 tx_hash : signed . id
@@ -873,7 +887,7 @@ ChainsqlAPI.prototype.getBySqlUser = function(sql){
873887ChainsqlAPI . prototype . submit = function ( cb ) {
874888 var that = this ;
875889 if ( that . transaction ) {
876- throw new Error ( 'you are now in transaction,can not be submit' )
890+ throw new Error ( 'you are now in transaction,can not be submit' ) ;
877891 } else {
878892
879893 //if (cb === undefined || cb === null) {
0 commit comments