This repository has been archived by the owner on Sep 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prepare and sign functionality to existing REST endpoints
- Loading branch information
Chris Clark
committed
Apr 20, 2015
1 parent
cc16a1a
commit 37508bb
Showing
28 changed files
with
320 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
'use strict'; | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
var sign = require('./transaction/sign'); | ||
var createTxJSON = require('./transaction/utils').createTxJSON; | ||
var transactions = require('./transactions'); | ||
var validate = require('./lib/validate'); | ||
|
||
function signIfSecretExists(secret, prepared, callback) { | ||
var signResponse = secret ? sign(prepared.tx_json, secret) : {}; | ||
callback(null, _.assign(prepared, signResponse)); | ||
} | ||
|
||
function formatResponse(converter, prepared, callback) { | ||
async.waterfall([ | ||
_.partial(converter, prepared, {}), | ||
function(formatted, _callback) { | ||
_callback(null, _.assign(formatted, prepared)); | ||
} | ||
], callback); | ||
} | ||
|
||
function prepareAndOptionallySign(transaction, api, secret, options, | ||
converter, callback) { | ||
var address = transaction.tx_json.Account; | ||
validate.addressAndMaybeSecret({address: address, secret: secret}); | ||
validate.options(options); | ||
async.waterfall([ | ||
_.partial(createTxJSON, transaction, api.remote, options), | ||
_.partial(signIfSecretExists, secret), | ||
_.partial(formatResponse, converter) | ||
], callback); | ||
} | ||
|
||
function prepareAndSignAndSubmit(transaction, api, secret, options, converter, | ||
callback) { | ||
var address = transaction.tx_json.Account; | ||
validate.addressAndSecret({address: address, secret: secret}); | ||
validate.options(options); | ||
async.waterfall([ | ||
_.partial(transactions.submit, api, transaction, secret, options), | ||
converter | ||
], callback); | ||
} | ||
|
||
/* eslint-disable no-unused-vars */ | ||
function transact(transaction, api, secret, options, converter, callback) { | ||
if (options.submit === false) { | ||
prepareAndOptionallySign.apply(this, arguments); | ||
} else { | ||
prepareAndSignAndSubmit.apply(this, arguments); | ||
} | ||
} | ||
/* eslint-enable no-unused-vars */ | ||
|
||
module.exports = transact; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.