Add support for AccountDelete (#1120)

https://xrpl.org/accountdelete.html
This commit is contained in:
Elliot Lee
2020-01-06 04:01:10 -08:00
committed by GitHub
parent 23504821cf
commit 138e7942da
19 changed files with 294 additions and 34 deletions

View File

@@ -62,6 +62,8 @@ function loadSchemas() {
require('./schemas/specifications/check-cash.json'),
require('./schemas/specifications/check-cancel.json'),
require('./schemas/specifications/trustline.json'),
require('./schemas/specifications/deposit-preauth.json'),
require('./schemas/specifications/account-delete.json'),
require('./schemas/output/sign.json'),
require('./schemas/output/submit.json'),
require('./schemas/output/get-account-info.json'),

View File

@@ -18,6 +18,8 @@
"paymentChannelClaim",
"checkCreate",
"checkCancel",
"checkCash"
"checkCash",
"depositPreauth",
"accountDelete"
]
}

View File

@@ -208,6 +208,30 @@
"$ref": "paymentChannelClaim"
}
}
},
{
"properties": {
"type": {
"enum": [
"depositPreauth"
]
},
"specification": {
"$ref": "depositPreauth"
}
}
},
{
"properties": {
"type": {
"enum": [
"accountDelete"
]
},
"specification": {
"$ref": "accountDelete"
}
}
}
]
}

View File

@@ -0,0 +1,29 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "accountDelete",
"link": "account-delete",
"type": "object",
"properties": {
"destination": {
"$ref": "address",
"description": "Address of an account to receive any leftover XRP after deleting the sending account. Must be a funded account in the ledger, and must not be the sending account."
},
"destinationTag": {
"$ref": "tag",
"description": "(Optional) Arbitrary destination tag that identifies a hosted recipient or other information for the recipient of the deleted account's leftover XRP."
},
"destinationXAddress": {
"$ref": "address",
"description": "X-address of an account to receive any leftover XRP after deleting the sending account. Must be a funded account in the ledger, and must not be the sending account."
}
},
"anyOf": [
{
"required": ["destination"]
},
{
"required": ["destinationXAddress"]
}
],
"additionalProperties": false
}

View File

@@ -0,0 +1,21 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "depositPreauth",
"link": "deposit-preauth",
"type": "object",
"properties": {
"authorize": {
"$ref": "address",
"description": "Address of the account that can cash the check."
},
"unauthorize": {
"$ref": "address",
"description": "Address of the account that can cash the check."
}
},
"oneOf": [
{"required": ["authorize"]},
{"required": ["unauthorize"]}
],
"additionalProperties": false
}

View File

@@ -0,0 +1,34 @@
import * as assert from 'assert'
import {removeUndefined} from '../../common'
import {classicAddressToXAddress} from 'ripple-address-codec'
export type FormattedAccountDelete = {
// account (address) of an account to receive any leftover XRP after deleting the sending account.
// Must be a funded account in the ledger, and must not be the sending account.
destination: string
// (Optional) Arbitrary destination tag that identifies a hosted recipient or other information
// for the recipient of the deleted account's leftover XRP. NB: Ensure that the hosted recipient is
// able to account for AccountDelete transactions; if not, your balance may not be properly credited.
destinationTag?: number
// X-address of an account to receive any leftover XRP after deleting the sending account.
// Must be a funded account in the ledger, and must not be the sending account.
destinationXAddress: string
}
function parseAccountDelete(tx: any): FormattedAccountDelete {
assert.ok(tx.TransactionType === 'AccountDelete')
return removeUndefined({
destination: tx.Destination,
destinationTag: tx.DestinationTag,
destinationXAddress: classicAddressToXAddress(
tx.Destination,
tx.DestinationTag === undefined ? false : tx.DestinationTag,
false
)
})
}
export default parseAccountDelete

View File

@@ -1,27 +1,31 @@
import {parseOutcome} from './utils'
import {removeUndefined} from '../../common'
import parsePayment from './payment'
import parseTrustline from './trustline'
import parseOrder from './order'
import parseOrderCancellation from './cancellation'
import parseSettings from './settings'
import parseAccountDelete from './account-delete'
import parseCheckCancel from './check-cancel'
import parseCheckCash from './check-cash'
import parseCheckCreate from './check-create'
import parseDepositPreauth from './deposit-preauth'
import parseEscrowCancellation from './escrow-cancellation'
import parseEscrowCreation from './escrow-creation'
import parseEscrowExecution from './escrow-execution'
import parseEscrowCancellation from './escrow-cancellation'
import parseCheckCreate from './check-create'
import parseCheckCash from './check-cash'
import parseCheckCancel from './check-cancel'
import parseDepositPreauth from './deposit-preauth'
import parseOrderCancellation from './cancellation'
import parseOrder from './order'
import parsePayment from './payment'
import parsePaymentChannelClaim from './payment-channel-claim'
import parsePaymentChannelCreate from './payment-channel-create'
import parsePaymentChannelFund from './payment-channel-fund'
import parsePaymentChannelClaim from './payment-channel-claim'
import parseFeeUpdate from './fee-update'
import parseAmendment from './amendment'
import parseTrustline from './trustline'
import parseAmendment from './amendment' // pseudo-transaction
import parseFeeUpdate from './fee-update' // pseudo-transaction
function parseTransactionType(type) {
// Ordering matches https://developers.ripple.com/transaction-types.html
const mapping = {
AccountSet: 'settings',
AccountDelete: 'accountDelete',
CheckCancel: 'checkCancel',
CheckCash: 'checkCash',
CheckCreate: 'checkCreate',
@@ -49,23 +53,25 @@ function parseTransactionType(type) {
function parseTransaction(tx: any, includeRawTransaction: boolean): any {
const type = parseTransactionType(tx.TransactionType)
const mapping = {
payment: parsePayment,
trustline: parseTrustline,
order: parseOrder,
orderCancellation: parseOrderCancellation,
settings: parseSettings,
accountDelete: parseAccountDelete,
checkCancel: parseCheckCancel,
checkCash: parseCheckCash,
checkCreate: parseCheckCreate,
depositPreauth: parseDepositPreauth,
escrowCancellation: parseEscrowCancellation,
escrowCreation: parseEscrowCreation,
escrowExecution: parseEscrowExecution,
escrowCancellation: parseEscrowCancellation,
checkCreate: parseCheckCreate,
checkCash: parseCheckCash,
checkCancel: parseCheckCancel,
depositPreauth: parseDepositPreauth,
orderCancellation: parseOrderCancellation,
order: parseOrder,
payment: parsePayment,
paymentChannelClaim: parsePaymentChannelClaim,
paymentChannelCreate: parsePaymentChannelCreate,
paymentChannelFund: parsePaymentChannelFund,
paymentChannelClaim: parsePaymentChannelClaim,
feeUpdate: parseFeeUpdate,
amendment: parseAmendment
trustline: parseTrustline,
amendment: parseAmendment, // pseudo-transaction
feeUpdate: parseFeeUpdate // pseudo-transaction
}
const parser: Function = mapping[type]