Checks (RIPD-1487):

Introduce a new ledger type: ltCHECK
Introduce three new transactions that operate on checks:

- "CheckCreate" which adds the check entry to the ledger.  The
  check is a promise from the source of the check that the
  destination of the check may cash the check and receive up to
  the SendMax specified on the check.  The check may have an
  expiration, after which the check may no longer be cashed.

- "CheckCash" is a request by the destination of the check to
  transfer a requested amount of funds, up to the check's SendMax,
  from the source to the destination.  The destination may receive
  less than the SendMax due to transfer fees.

  When cashing a check, the destination specifies the smallest
  amount of funds that will be acceptable.  If the transfer
  completes and delivers the requested amount, then the check is
  considered cashed and removed from the ledger.  If enough funds
  cannot be delivered, then the transaction fails and the check
  remains in the ledger.

  Attempting to cash the check after its expiration will fail.

- "CheckCancel" removes the check from the ledger without
  transferring funds.  Either the check's source or destination
  can cancel the check at any time.  After a check has expired,
  any account can cancel the check.

Facilities related to checks are on the "Checks" amendment.
This commit is contained in:
Scott Schurr
2017-10-13 13:52:41 -07:00
parent 76ad06ef47
commit 2d5ddbf1bf
31 changed files with 2981 additions and 107 deletions

View File

@@ -107,7 +107,8 @@ detail::supportedAmendments ()
{ "67A34F2CF55BFC0F93AACD5B281413176FEE195269FA6D95219A2DF738671172 fix1513" },
{ "B9E739B8296B4A1BB29BE990B17D66E21B62A300A909F25AC55C22D6C72E1F9D fix1523" },
{ "1D3463A5891F9E589C5AE839FFAC4A917CE96197098A1EF22304E1BC5B98A454 fix1528" },
{ "F64E1EABBE79D55B3BB82020516CEC2C582A98A6BFE20FBE9BB6A0D233418064 DepositAuth"}
{ "F64E1EABBE79D55B3BB82020516CEC2C582A98A6BFE20FBE9BB6A0D233418064 DepositAuth"},
{ "157D2D480E006395B76F948E3E07A45A05FE10230D88A7993C71F97AE4B1F2D1 Checks"}
};
return supported;
}
@@ -156,5 +157,6 @@ uint256 const fix1513 = *getRegisteredFeature("fix1513");
uint256 const fix1523 = *getRegisteredFeature("fix1523");
uint256 const fix1528 = *getRegisteredFeature("fix1528");
uint256 const featureDepositAuth = *getRegisteredFeature("DepositAuth");
uint256 const featureChecks = *getRegisteredFeature("Checks");
} // ripple

View File

@@ -190,6 +190,15 @@ getSignerListIndex (AccountID const& account)
std::uint32_t (0)); // 0 == default SignerList ID.
}
uint256
getCheckIndex (AccountID const& account, std::uint32_t uSequence)
{
return sha512Half(
std::uint16_t(spaceCheck),
account,
std::uint32_t(uSequence));
}
//------------------------------------------------------------------------------
namespace keylet {
@@ -285,6 +294,13 @@ Keylet signers_t::operator()(AccountID const& id) const
getSignerListIndex(id) };
}
Keylet check_t::operator()(AccountID const& id,
std::uint32_t seq) const
{
return { ltCHECK,
getCheckIndex(id, seq) };
}
//------------------------------------------------------------------------------
Keylet unchecked (uint256 const& key)

View File

@@ -87,19 +87,20 @@ LedgerFormats::LedgerFormats ()
<< SOElement (sfHighQualityOut, SOE_OPTIONAL)
;
add ("Escrow", ltESCROW) <<
SOElement (sfAccount, SOE_REQUIRED) <<
SOElement (sfDestination, SOE_REQUIRED) <<
SOElement (sfAmount, SOE_REQUIRED) <<
SOElement (sfCondition, SOE_OPTIONAL) <<
SOElement (sfCancelAfter, SOE_OPTIONAL) <<
SOElement (sfFinishAfter, SOE_OPTIONAL) <<
SOElement (sfSourceTag, SOE_OPTIONAL) <<
SOElement (sfDestinationTag, SOE_OPTIONAL) <<
SOElement (sfOwnerNode, SOE_REQUIRED) <<
SOElement (sfPreviousTxnID, SOE_REQUIRED) <<
SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED) <<
SOElement (sfDestinationNode, SOE_OPTIONAL);
add ("Escrow", ltESCROW)
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfCondition, SOE_OPTIONAL)
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
<< SOElement (sfFinishAfter, SOE_OPTIONAL)
<< SOElement (sfSourceTag, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
<< SOElement (sfOwnerNode, SOE_REQUIRED)
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
<< SOElement (sfDestinationNode, SOE_OPTIONAL)
;
add ("LedgerHashes", ltLEDGER_HASHES)
<< SOElement (sfFirstLedgerSequence, SOE_OPTIONAL) // Remove if we do a ledger restart
@@ -139,19 +140,34 @@ LedgerFormats::LedgerFormats ()
;
add ("PayChannel", ltPAYCHAN)
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfBalance, SOE_REQUIRED)
<< SOElement (sfPublicKey, SOE_REQUIRED)
<< SOElement (sfSettleDelay, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
<< SOElement (sfSourceTag, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
<< SOElement (sfOwnerNode, SOE_REQUIRED)
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfBalance, SOE_REQUIRED)
<< SOElement (sfPublicKey, SOE_REQUIRED)
<< SOElement (sfSettleDelay, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
<< SOElement (sfSourceTag, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
<< SOElement (sfOwnerNode, SOE_REQUIRED)
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
;
add ("Check", ltCHECK)
<< SOElement (sfAccount, SOE_REQUIRED)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfSendMax, SOE_REQUIRED)
<< SOElement (sfSequence, SOE_REQUIRED)
<< SOElement (sfOwnerNode, SOE_REQUIRED)
<< SOElement (sfDestinationNode, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
<< SOElement (sfInvoiceID, SOE_OPTIONAL)
<< SOElement (sfSourceTag, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
<< SOElement (sfPreviousTxnID, SOE_REQUIRED)
<< SOElement (sfPreviousTxnLgrSeq, SOE_REQUIRED)
;
}

View File

@@ -171,6 +171,7 @@ SF_U256 const sfTicketID = make::one<SF_U256::type>(&sfTicketID, STI_H
SF_U256 const sfDigest = make::one<SF_U256::type>(&sfDigest, STI_HASH256, 21, "Digest");
SF_U256 const sfPayChannel = make::one<SF_U256::type>(&sfPayChannel, STI_HASH256, 22, "Channel");
SF_U256 const sfConsensusHash = make::one<SF_U256::type>(&sfConsensusHash, STI_HASH256, 23, "ConsensusHash");
SF_U256 const sfCheckID = make::one<SF_U256::type>(&sfCheckID, STI_HASH256, 24, "CheckID");
// currency amount (common)
SF_Amount const sfAmount = make::one<SF_Amount::type>(&sfAmount, STI_AMOUNT, 1, "Amount");

View File

@@ -72,6 +72,7 @@ transResults()
{ tecINTERNAL, { "tecINTERNAL", "An internal error has occurred during processing." } },
{ tecCRYPTOCONDITION_ERROR, { "tecCRYPTOCONDITION_ERROR", "Malformed, invalid, or mismatched conditional or fulfillment." } },
{ tecINVARIANT_FAILED, { "tecINVARIANT_FAILED", "One or more invariants for the transaction were not satisfied." } },
{ tecEXPIRED, { "tecEXPIRED", "Expiration time is passed." } },
{ tefALREADY, { "tefALREADY", "The exact transaction was already in this ledger." } },
{ tefBAD_ADD_AUTH, { "tefBAD_ADD_AUTH", "Not authorized to add account." } },

View File

@@ -67,23 +67,26 @@ TxFormats::TxFormats ()
<< SOElement (sfDeliverMin, SOE_OPTIONAL)
;
add ("EscrowCreate", ttESCROW_CREATE) <<
SOElement (sfDestination, SOE_REQUIRED) <<
SOElement (sfAmount, SOE_REQUIRED) <<
SOElement (sfCondition, SOE_OPTIONAL) <<
SOElement (sfCancelAfter, SOE_OPTIONAL) <<
SOElement (sfFinishAfter, SOE_OPTIONAL) <<
SOElement (sfDestinationTag, SOE_OPTIONAL);
add ("EscrowCreate", ttESCROW_CREATE)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfCondition, SOE_OPTIONAL)
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
<< SOElement (sfFinishAfter, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
;
add ("EscrowFinish", ttESCROW_FINISH) <<
SOElement (sfOwner, SOE_REQUIRED) <<
SOElement (sfOfferSequence, SOE_REQUIRED) <<
SOElement (sfFulfillment, SOE_OPTIONAL) <<
SOElement (sfCondition, SOE_OPTIONAL);
add ("EscrowFinish", ttESCROW_FINISH)
<< SOElement (sfOwner, SOE_REQUIRED)
<< SOElement (sfOfferSequence, SOE_REQUIRED)
<< SOElement (sfFulfillment, SOE_OPTIONAL)
<< SOElement (sfCondition, SOE_OPTIONAL)
;
add ("EscrowCancel", ttESCROW_CANCEL) <<
SOElement (sfOwner, SOE_REQUIRED) <<
SOElement (sfOfferSequence, SOE_REQUIRED);
add ("EscrowCancel", ttESCROW_CANCEL)
<< SOElement (sfOwner, SOE_REQUIRED)
<< SOElement (sfOfferSequence, SOE_REQUIRED)
;
add ("EnableAmendment", ttAMENDMENT)
<< SOElement (sfLedgerSequence, SOE_REQUIRED)
@@ -114,44 +117,65 @@ TxFormats::TxFormats ()
<< SOElement (sfSignerEntries, SOE_OPTIONAL)
;
add ("PaymentChannelCreate", ttPAYCHAN_CREATE) <<
SOElement (sfDestination, SOE_REQUIRED) <<
SOElement (sfAmount, SOE_REQUIRED) <<
SOElement (sfSettleDelay, SOE_REQUIRED) <<
SOElement (sfPublicKey, SOE_REQUIRED) <<
SOElement (sfCancelAfter, SOE_OPTIONAL) <<
SOElement (sfDestinationTag, SOE_OPTIONAL);
add ("PaymentChannelCreate", ttPAYCHAN_CREATE)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfSettleDelay, SOE_REQUIRED)
<< SOElement (sfPublicKey, SOE_REQUIRED)
<< SOElement (sfCancelAfter, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
;
add ("PaymentChannelFund", ttPAYCHAN_FUND) <<
SOElement (sfPayChannel, SOE_REQUIRED) <<
SOElement (sfAmount, SOE_REQUIRED) <<
SOElement (sfExpiration, SOE_OPTIONAL);
add ("PaymentChannelFund", ttPAYCHAN_FUND)
<< SOElement (sfPayChannel, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
;
add ("PaymentChannelClaim", ttPAYCHAN_CLAIM) <<
SOElement (sfPayChannel, SOE_REQUIRED) <<
SOElement (sfAmount, SOE_OPTIONAL) <<
SOElement (sfBalance, SOE_OPTIONAL) <<
SOElement (sfSignature, SOE_OPTIONAL) <<
SOElement (sfPublicKey, SOE_OPTIONAL);
add ("PaymentChannelClaim", ttPAYCHAN_CLAIM)
<< SOElement (sfPayChannel, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_OPTIONAL)
<< SOElement (sfBalance, SOE_OPTIONAL)
<< SOElement (sfSignature, SOE_OPTIONAL)
<< SOElement (sfPublicKey, SOE_OPTIONAL)
;
add ("CheckCreate", ttCHECK_CREATE)
<< SOElement (sfDestination, SOE_REQUIRED)
<< SOElement (sfSendMax, SOE_REQUIRED)
<< SOElement (sfExpiration, SOE_OPTIONAL)
<< SOElement (sfDestinationTag, SOE_OPTIONAL)
<< SOElement (sfInvoiceID, SOE_OPTIONAL)
;
add ("CheckCash", ttCHECK_CASH)
<< SOElement (sfCheckID, SOE_REQUIRED)
<< SOElement (sfAmount, SOE_OPTIONAL)
<< SOElement (sfDeliverMin, SOE_OPTIONAL)
;
add ("CheckCancel", ttCHECK_CANCEL)
<< SOElement (sfCheckID, SOE_REQUIRED)
;
}
void TxFormats::addCommonFields (Item& item)
{
item
<< SOElement(sfTransactionType, SOE_REQUIRED)
<< SOElement(sfFlags, SOE_OPTIONAL)
<< SOElement(sfSourceTag, SOE_OPTIONAL)
<< SOElement(sfAccount, SOE_REQUIRED)
<< SOElement(sfSequence, SOE_REQUIRED)
<< SOElement(sfPreviousTxnID, SOE_OPTIONAL) // emulate027
<< SOElement(sfLastLedgerSequence, SOE_OPTIONAL)
<< SOElement(sfAccountTxnID, SOE_OPTIONAL)
<< SOElement(sfFee, SOE_REQUIRED)
<< SOElement(sfOperationLimit, SOE_OPTIONAL)
<< SOElement(sfMemos, SOE_OPTIONAL)
<< SOElement(sfSigningPubKey, SOE_REQUIRED)
<< SOElement(sfTxnSignature, SOE_OPTIONAL)
<< SOElement(sfSigners, SOE_OPTIONAL) // submit_multisigned
<< SOElement(sfTransactionType, SOE_REQUIRED)
<< SOElement(sfFlags, SOE_OPTIONAL)
<< SOElement(sfSourceTag, SOE_OPTIONAL)
<< SOElement(sfAccount, SOE_REQUIRED)
<< SOElement(sfSequence, SOE_REQUIRED)
<< SOElement(sfPreviousTxnID, SOE_OPTIONAL) // emulate027
<< SOElement(sfLastLedgerSequence, SOE_OPTIONAL)
<< SOElement(sfAccountTxnID, SOE_OPTIONAL)
<< SOElement(sfFee, SOE_REQUIRED)
<< SOElement(sfOperationLimit, SOE_OPTIONAL)
<< SOElement(sfMemos, SOE_OPTIONAL)
<< SOElement(sfSigningPubKey, SOE_REQUIRED)
<< SOElement(sfTxnSignature, SOE_OPTIONAL)
<< SOElement(sfSigners, SOE_OPTIONAL) // submit_multisigned
;
}