Skip to content
This repository has been archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #173 from ripple/remove-storage-interface
Browse files Browse the repository at this point in the history
Do not use ripple-lib storage interface
  • Loading branch information
geertweening committed Oct 10, 2014
2 parents 094be1f + d36885a commit 7b32508
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
27 changes: 19 additions & 8 deletions api/transactions.js
Expand Up @@ -34,18 +34,19 @@ module.exports = {
* @param {submission response} response The response received from the 'proposed' event
*/
function submitTransaction(data, response, callback) {

function prepareTransaction(async_callback) {
data.transaction.secret(data.secret);
data.transaction.clientID(data.client_resource_id);
async_callback(null, data.transaction);
};

function blockDuplicates(transaction, async_callback) {
function blockDuplicates(transaction, async_callback) {
var type = transaction.tx_json.TransactionType;

if (type !== 'Payment' && type !== 'OfferCreate' && type !== 'OfferCancel') {
return async_callback(null, transaction);
}

dbinterface.getTransaction({
source_account: transaction.tx_json.Account,
client_resource_id: data.client_resource_id,
Expand All @@ -54,6 +55,7 @@ function submitTransaction(data, response, callback) {
if (error) {
return async_callback(error);
}

if (db_record && db_record.state !== 'failed') {
async_callback(new errors.ApiError('Duplicate Transaction. ' +
'A record already exists in the database for a transaction of this type ' +
Expand All @@ -70,10 +72,7 @@ function submitTransaction(data, response, callback) {
transaction.remote = remote;

var ledgerIndex = remote._ledger_current_index;

if (!isNaN(ledgerIndex)) {
transaction.lastLedger(Number(ledgerIndex) + module.exports.DEFAULT_LEDGER_BUFFER);
}
transaction.lastLedger(Number(ledgerIndex) + module.exports.DEFAULT_LEDGER_BUFFER);

transaction.once('error', async_callback);

Expand All @@ -82,6 +81,20 @@ function submitTransaction(data, response, callback) {
async_callback(null, transaction._clientID);
});

function saveTransaction() {
dbinterface.saveTransaction(transaction.summary());
};

transaction.once('proposed', function() {
saveTransaction();

// Save transaction after every subsequent submission
transaction.on('submitted', saveTransaction);

// Save on state change
transaction.on('state', saveTransaction);
});

transaction.submit();
};

Expand Down Expand Up @@ -250,7 +263,6 @@ function getTransactionHelper(request, response, callback) {
async_callback(null, transaction);
});
};

};

/**
Expand Down Expand Up @@ -280,7 +292,6 @@ function getTransactionHelper(request, response, callback) {
* @param {Array of transactions in JSON format} transactions
*/
function getAccountTransactions(options, response, callback) {

var steps = [
validateOptions,
queryTransactions,
Expand Down
8 changes: 3 additions & 5 deletions lib/db-interface.js
Expand Up @@ -150,6 +150,8 @@ DI.saveTransaction = function(transaction, callback) {
assert(transaction.tx_json.Account,
'Transaction missing property: tx_json.Account');
//assert(transaction.clientID, 'Transaction missing property: clientID');

// Transaction shouldn't be saved unless it was successfully submitted
assert(transaction.submitIndex,
'Transaction missing property: submitIndex');
assert(transaction.submittedIDs,
Expand Down Expand Up @@ -207,11 +209,7 @@ DI.saveTransaction = function(transaction, callback) {

var info = txData.hash + ': ' + txData.rippled_result;

if (txData.finalized) {
logger.info('[DB] Saved transaction: finalized: ' + info);
} else if (txData.state === 'submitted') {
logger.info('[DB] Saved transaction: submitted: ' + info);
}
logger.info('[DB] Saved transaction: ' + txData.state + ': ' + info);

return res;
})
Expand Down
3 changes: 1 addition & 2 deletions lib/remote.js
Expand Up @@ -4,8 +4,7 @@ var dbinterface = require('./db-interface');
var logger = require('./logger.js').logger;

var remoteOpts = {
servers: config.get('rippled_servers'),
storage: dbinterface
servers: config.get('rippled_servers')
};

if (config.get('debug')) {
Expand Down

0 comments on commit 7b32508

Please sign in to comment.