@ -53,7 +53,6 @@ module.exports = (shepherd) => {
if ( json &&
if ( json &&
json . length ) {
json . length ) {
let _ rawtx = [ ] ;
let _ rawtx = [ ] ;
let _ inputTxs = { } ;
json = shepherd . sortTransactions ( json ) ;
json = shepherd . sortTransactions ( json ) ;
json = json . length > MAX_TX ? json . slice ( 0 , MAX_TX ) : json ;
json = json . length > MAX_TX ? json . slice ( 0 , MAX_TX ) : json ;
@ -63,16 +62,20 @@ module.exports = (shepherd) => {
const _ getTransaction = ( txid ) => {
const _ getTransaction = ( txid ) => {
return new shepherd . Promise ( ( resolve , reject ) => {
return new shepherd . Promise ( ( resolve , reject ) => {
if ( ! _ inputTxs [ txid ] ) {
if ( ! shepherd . electrumCache [ network ] ) {
shepherd . electrumCache [ network ] = { } ;
}
if ( ! shepherd . electrumCache [ network ] [ txid ] ) {
ecl . blockchainTransactionGet ( txid )
ecl . blockchainTransactionGet ( txid )
. then ( ( _ rawtxJSON ) => {
. then ( ( _ rawtxJSON ) => {
resolve ( _ rawtxJSON ) ;
resolve ( _ rawtxJSON ) ;
} ) ;
} ) ;
} else {
} else {
resolve ( _ inputTxs [ txid ] ) ;
resolve ( shepherd . electrumCache [ network ] [ txid ] ) ;
}
}
} ) ;
} ) ;
} ;
}
async . eachOfSeries ( json , ( transaction , ind , callback ) => {
async . eachOfSeries ( json , ( transaction , ind , callback ) => {
ecl . blockchainBlockGetHeader ( transaction . height )
ecl . blockchainBlockGetHeader ( transaction . height )
@ -81,8 +84,8 @@ module.exports = (shepherd) => {
blockInfo . timestamp ) {
blockInfo . timestamp ) {
_ getTransaction ( transaction [ 'tx_hash' ] )
_ getTransaction ( transaction [ 'tx_hash' ] )
. then ( ( _ rawtxJSON ) => {
. then ( ( _ rawtxJSON ) => {
if ( ! _ inputTxs [ transaction [ 'tx_hash' ] ] ) {
if ( ! shepherd . electrumCache [ network ] [ transaction [ 'tx_hash' ] ] ) {
_ inputTxs [ transaction [ 'tx_hash' ] ] = _ rawtxJSON ;
shepherd . electrumCache [ network ] [ transaction [ 'tx_hash' ] ] = _ rawtxJSON ;
}
}
shepherd . log ( 'electrum gettransaction ==>' , true ) ;
shepherd . log ( 'electrum gettransaction ==>' , true ) ;
shepherd . log ( ( index + ' | ' + ( _ rawtxJSON . length - 1 ) ) , true ) ;
shepherd . log ( ( index + ' | ' + ( _ rawtxJSON . length - 1 ) ) , true ) ;
@ -167,10 +170,10 @@ module.exports = (shepherd) => {
}
}
if ( _ decodedInput . txid !== '0000000000000000000000000000000000000000000000000000000000000000' ) {
if ( _ decodedInput . txid !== '0000000000000000000000000000000000000000000000000000000000000000' ) {
if ( ! _ inputTxs [ _ decodedInput . txid ] ) {
if ( ! shepherd . electrumCache [ network ] [ _ decodedInput . txid ] ) {
ecl . blockchainTransactionGet ( _ decodedInput . txid )
ecl . blockchainTransactionGet ( _ decodedInput . txid )
. then ( ( rawInput ) => {
. then ( ( rawInput ) => {
_ inputTxs [ _ decodedInput . txid ] = rawInput ;
shepherd . electrumCache [ network ] [ _ decodedInput . txid ] = rawInput ;
const decodedVinVout = shepherd . electrumJSTxDecoder ( rawInput , network , _ network ) ;
const decodedVinVout = shepherd . electrumJSTxDecoder ( rawInput , network , _ network ) ;
@ -183,9 +186,9 @@ module.exports = (shepherd) => {
checkLoop ( ) ;
checkLoop ( ) ;
} ) ;
} ) ;
} else {
} else {
const decodedVinVout = shepherd . electrumJSTxDecoder ( _ inputTxs [ _ decodedInput . txid ] , network , _ network ) ;
const decodedVinVout = shepherd . electrumJSTxDecoder ( shepherd . electrumCache [ network ] [ _ decodedInput . txid ] , network , _ network ) ;
shepherd . log ( ` electrum raw one time cached input tx ${ _ decodedInput . txid } ==> ` , true ) ;
shepherd . log ( ` electrum raw cached input tx ${ _ decodedInput . txid } ==> ` , true ) ;
if ( decodedVinVout ) {
if ( decodedVinVout ) {
shepherd . log ( decodedVinVout . outputs [ _ decodedInput . n ] , true ) ;
shepherd . log ( decodedVinVout . outputs [ _ decodedInput . n ] , true ) ;
@ -527,9 +530,10 @@ module.exports = (shepherd) => {
} else {
} else {
const ecl = new shepherd . electrumJSCore ( shepherd . electrumServers [ req . query . network ] . port , shepherd . electrumServers [ req . query . network ] . address , shepherd . electrumServers [ req . query . network ] . proto ) ; // tcp or tls
const ecl = new shepherd . electrumJSCore ( shepherd . electrumServers [ req . query . network ] . port , shepherd . electrumServers [ req . query . network ] . address , shepherd . electrumServers [ req . query . network ] . proto ) ; // tcp or tls
ecl . connect ( ) ;
shepherd . log ( decodedTx . inputs [ 0 ] ) ;
shepherd . log ( decodedTx . inputs [ 0 ] ) ;
shepherd . log ( decodedTx . inputs [ 0 ] . txid ) ;
shepherd . log ( decodedTx . inputs [ 0 ] . txid ) ;
ecl . connect ( ) ;
ecl . blockchainTransactionGet ( decodedTx . inputs [ 0 ] . txid )
ecl . blockchainTransactionGet ( decodedTx . inputs [ 0 ] . txid )
. then ( ( json ) => {
. then ( ( json ) => {
ecl . close ( ) ;
ecl . close ( ) ;