rippleapi quickstart - improve code sample

This commit is contained in:
mDuo13
2016-01-27 17:13:46 -08:00
parent d2f9d39144
commit dbf45774f4
2 changed files with 22 additions and 24 deletions

View File

@@ -11,27 +11,26 @@ const my_secret = 's████████████████████
const my_order = {
'direction': 'buy',
'quantity': {
'currency': '',
'counterparty': '',
'value': ''
'currency': 'FOO',
'counterparty': 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v',
'value': '100'
},
'totalPrice': {
'currency': '',
'counterparty': '',
'value': ''
'currency': 'XRP',
'value': '1000'
}
};
/* milliseconds to wait between ledger checks*/
/* Milliseconds to wait between checks for a new ledger. */
const INTERVAL = 1000;
/* Instantiate RippleAPI */
const api = new RippleAPI({server: 'wss://s1.ripple.com'});
/* Instantiate RippleAPI. Uses s2 (full history server) */
const api = new RippleAPI({server: 'wss://s2.ripple.com'});
/* number of ledgers to check for valid transaction before fail */
const ledgerOffset = 5;
const my_instructions = {maxLedgerVersionOffset: ledgerOffset};
/* function to verify a transaction is on the RCL */
/* Verify a transaction is in a validated RCL version */
function verifyTransaction(hash, options) {
console.log('Verifing Transaction');
return api.getTransaction(hash, options).then(data => {
@@ -40,14 +39,14 @@ function verifyTransaction(hash, options) {
console.log('Sequence: ', data.sequence);
return data.outcome.result === 'tesSUCCESS';
}).catch(error => {
/* if transaction not on current ledger try again until max ledger hit */
/* if transaction not in latest validated ledger try again until max ledger hit */
if (error instanceof api.errors.PendingLedgerVersionError) {
return new Promise((resolve, reject) => {
setTimeout(() => verifyTransaction(hash, options)
.then(resolve, reject), INTERVAL);
});
}
return result;// TODO: Fix this. It's currently undefined.
return error;
});
}

View File

@@ -305,27 +305,26 @@ const my_secret = 's████████████████████
const my_order = {
'direction': 'buy',
'quantity': {
'currency': '',
'counterparty': '',
'value': ''
'currency': 'FOO',
'counterparty': 'rUpy3eEg8rqjqfUoLeBnZkscbKbFsKXC3v',
'value': '100'
},
'totalPrice': {
'currency': '',
'counterparty': '',
'value': ''
'currency': 'XRP',
'value': '1000'
}
};
/* milliseconds to wait between ledger checks*/
/* Milliseconds to wait between checks for a new ledger. */
const INTERVAL = 1000;
/* Instantiate RippleAPI */
const api = new RippleAPI({server: 'wss://s1.ripple.com'});
/* Instantiate RippleAPI. Uses s2 (full history server) */
const api = new RippleAPI({server: 'wss://s2.ripple.com'});
/* number of ledgers to check for valid transaction before fail */
const ledgerOffset = 5;
const my_instructions = {maxLedgerVersionOffset: ledgerOffset};
/* function to verify a transaction is on the RCL */
/* Verify a transaction is in a validated RCL version */
function verifyTransaction(hash, options) {
console.log('Verifing Transaction');
return api.getTransaction(hash, options).then(data => {
@@ -334,14 +333,14 @@ function verifyTransaction(hash, options) {
console.log('Sequence: ', data.sequence);
return data.outcome.result === 'tesSUCCESS';
}).catch(error => {
/* if transaction not on current ledger try again until max ledger hit */
/* if transaction not in latest validated ledger try again until max ledger hit */
if (error instanceof api.errors.PendingLedgerVersionError) {
return new Promise((resolve, reject) => {
setTimeout(() => verifyTransaction(hash, options)
.then(resolve, reject), INTERVAL);
});
}
return result;// TODO: Fix this. It's currently undefined.
return error;
});
}