-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SuspendedPayment{Create,Finish,Cancel}
* Add SusPay core tests * Rename SusPay -> SuspendedPayment (code review) * Rename cancelAfter -> allowCancelAfter * Rename suspendedPayment{Finish,Execution}
- Loading branch information
1 parent
6e98629
commit b134081
Showing
29 changed files
with
733 additions
and
31 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
17 changes: 17 additions & 0 deletions
17
src/api/common/schemas/suspended-payment-cancellation.json
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,17 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "suspended-payment-cancellation", | ||
"type": "object", | ||
"properties": { | ||
"memos": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "memo" | ||
} | ||
}, | ||
"owner": {"$ref": "address"}, | ||
"paymentSequence": {"$ref": "uint32"} | ||
}, | ||
"required": ["owner", "paymentSequence"], | ||
"additionalProperties": false | ||
} |
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,28 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "suspended-payment-creation", | ||
"type": "object", | ||
"properties": { | ||
"source": {"$ref": "maxAdjustment"}, | ||
"destination": {"$ref": "adjustment"}, | ||
"memos": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "memo" | ||
} | ||
}, | ||
"digest": {"$ref": "hash256"}, | ||
"allowCancelAfter": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"description": "milliseconds since unix epoch" | ||
}, | ||
"allowExecuteAfter": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"description": "milliseconds since unix epoch" | ||
} | ||
}, | ||
"required": ["source", "destination"], | ||
"additionalProperties": false | ||
} |
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,20 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"title": "suspended-payment-execution", | ||
"type": "object", | ||
"properties": { | ||
"memos": { | ||
"type": "array", | ||
"items": { | ||
"$ref": "memo" | ||
} | ||
}, | ||
"owner": {"$ref": "address"}, | ||
"paymentSequence": {"$ref": "uint32"}, | ||
"method": {"type": "integer", "minimum": 0, "maximum": 255}, | ||
"digest": {"$ref": "hash256"}, | ||
"proof": {"type": "string"} | ||
}, | ||
"required": ["owner", "paymentSequence"], | ||
"additionalProperties": false | ||
} |
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,16 @@ | ||
/* @flow */ | ||
'use strict'; | ||
const assert = require('assert'); | ||
const utils = require('./utils'); | ||
|
||
function parseSuspendedPaymentCancellation(tx: Object): Object { | ||
assert(tx.TransactionType === 'SuspendedPaymentCancel'); | ||
|
||
return utils.removeUndefined({ | ||
memos: utils.parseMemos(tx), | ||
owner: tx.Owner, | ||
paymentSequence: tx.OfferSequence | ||
}); | ||
} | ||
|
||
module.exports = parseSuspendedPaymentCancellation; |
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,39 @@ | ||
/* @flow */ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
const assert = require('assert'); | ||
const utils = require('./utils'); | ||
const parseAmount = require('./amount'); | ||
|
||
function removeGenericCounterparty(amount, address) { | ||
return amount.counterparty === address ? | ||
_.omit(amount, 'counterparty') : amount; | ||
} | ||
|
||
function parseSuspendedPaymentCreation(tx: Object): Object { | ||
assert(tx.TransactionType === 'SuspendedPaymentCreate'); | ||
|
||
const source = { | ||
address: tx.Account, | ||
maxAmount: removeGenericCounterparty( | ||
parseAmount(tx.SendMax || tx.Amount), tx.Account), | ||
tag: tx.SourceTag | ||
}; | ||
|
||
const destination = { | ||
address: tx.Destination, | ||
amount: removeGenericCounterparty(parseAmount(tx.Amount), tx.Destination), | ||
tag: tx.DestinationTag | ||
}; | ||
|
||
return utils.removeUndefined({ | ||
source: utils.removeUndefined(source), | ||
destination: utils.removeUndefined(destination), | ||
memos: utils.parseMemos(tx), | ||
digest: tx.Digest, | ||
allowCancelAfter: tx.CancelAfter, | ||
allowExecuteAfter: tx.FinishAfter | ||
}); | ||
} | ||
|
||
module.exports = parseSuspendedPaymentCreation; |
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,25 @@ | ||
/* @flow */ | ||
'use strict'; | ||
const assert = require('assert'); | ||
const sjclcodec = require('sjcl-codec'); | ||
const utils = require('./utils'); | ||
|
||
function convertHexToString(hexString) { | ||
const bits = sjclcodec.hex.toBits(hexString); | ||
return sjclcodec.utf8String.fromBits(bits); | ||
} | ||
|
||
function parseSuspendedPaymentExecution(tx: Object): Object { | ||
assert(tx.TransactionType === 'SuspendedPaymentFinish'); | ||
|
||
return utils.removeUndefined({ | ||
memos: utils.parseMemos(tx), | ||
owner: tx.Owner, | ||
paymentSequence: tx.OfferSequence, | ||
method: tx.Method, | ||
digest: tx.Digest, | ||
proof: tx.Proof ? convertHexToString(tx.Proof) : undefined | ||
}); | ||
} | ||
|
||
module.exports = parseSuspendedPaymentExecution; |
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,40 @@ | ||
/* @flow */ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
const utils = require('./utils'); | ||
const validate = utils.common.validate; | ||
const Transaction = utils.common.core.Transaction; | ||
|
||
function createSuspendedPaymentCancellationTransaction(account, payment) { | ||
validate.address(account); | ||
validate.suspendedPaymentCancellation(payment); | ||
|
||
const transaction = new Transaction(); | ||
transaction.suspendedPaymentCancel({ | ||
account: account, | ||
owner: payment.owner, | ||
paymentSequence: payment.paymentSequence | ||
}); | ||
|
||
if (payment.memos) { | ||
_.forEach(payment.memos, memo => | ||
transaction.addMemo(memo.type, memo.format, memo.data) | ||
); | ||
} | ||
return transaction; | ||
} | ||
|
||
function prepareSuspendedPaymentCancellationAsync(account, payment, | ||
instructions, callback) { | ||
const transaction = | ||
createSuspendedPaymentCancellationTransaction(account, payment); | ||
utils.prepareTransaction(transaction, this.remote, instructions, callback); | ||
} | ||
|
||
function prepareSuspendedPaymentCancellation(account: string, payment: Object, | ||
instructions = {}) { | ||
return utils.promisify(prepareSuspendedPaymentCancellationAsync) | ||
.call(this, account, payment, instructions); | ||
} | ||
|
||
module.exports = prepareSuspendedPaymentCancellation; |
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,57 @@ | ||
/* @flow */ | ||
'use strict'; | ||
const _ = require('lodash'); | ||
const utils = require('./utils'); | ||
const validate = utils.common.validate; | ||
const toRippledAmount = utils.common.toRippledAmount; | ||
const Transaction = utils.common.core.Transaction; | ||
|
||
function createSuspendedPaymentCreationTransaction(account, payment) { | ||
validate.address(account); | ||
validate.suspendedPaymentCreation(payment); | ||
|
||
const transaction = new Transaction(); | ||
transaction.suspendedPaymentCreate({ | ||
account: account, | ||
destination: payment.destination.address, | ||
amount: toRippledAmount(payment.destination.amount) | ||
}); | ||
|
||
if (payment.digest) { | ||
transaction.setDigest(payment.digest); | ||
} | ||
if (payment.allowCancelAfter) { | ||
transaction.setAllowCancelAfter(payment.allowCancelAfter); | ||
} | ||
if (payment.allowExecuteAfter) { | ||
transaction.setAllowExecuteAfter(payment.allowExecuteAfter); | ||
} | ||
|
||
if (payment.source.tag) { | ||
transaction.sourceTag(payment.source.tag); | ||
} | ||
if (payment.destination.tag) { | ||
transaction.destinationTag(payment.destination.tag); | ||
} | ||
if (payment.memos) { | ||
_.forEach(payment.memos, memo => | ||
transaction.addMemo(memo.type, memo.format, memo.data) | ||
); | ||
} | ||
return transaction; | ||
} | ||
|
||
function prepareSuspendedPaymentCreationAsync(account, payment, instructions, | ||
callback) { | ||
const transaction = | ||
createSuspendedPaymentCreationTransaction(account, payment); | ||
utils.prepareTransaction(transaction, this.remote, instructions, callback); | ||
} | ||
|
||
function prepareSuspendedPaymentCreation(account: string, payment: Object, | ||
instructions = {}) { | ||
return utils.promisify(prepareSuspendedPaymentCreationAsync) | ||
.call(this, account, payment, instructions); | ||
} | ||
|
||
module.exports = prepareSuspendedPaymentCreation; |
Oops, something went wrong.