Esempio n. 1
0
const Identifier PaymentCode::ID() const
{

    uint8_t core[65]{};

    OTData pubkey = Pubkey();
    OTPassword::safe_memcpy(
        &core[0],
        33,
        pubkey.GetPointer(),
        pubkey.GetSize(),
        false);
    if (chain_code_.GetSize() == 32) {
        OTPassword::safe_memcpy(
            &core[33],
            32,
            chain_code_.GetPointer(),
            chain_code_.GetSize(),
            false);
    }

    OTData dataVersion(core, sizeof(core));

    Identifier paymentCodeID;

    paymentCodeID.CalculateDigest(dataVersion);

    return paymentCodeID;
}
Esempio n. 2
0
/*
 Let's say you wanted to add an Offer to a Market. But you don't know
 which market.  There are different markets for different combinations
 of asset and currency. There are also higher and lower level markets
 for different trade minimums.

 The server has to be able to match up your Offer to the Right Market,
 so that it can trade with similar offers.

 So in this method, I combine the Instrument Definition ID, the Currency Type
 ID,
 and the minimum increment, and use them to generate a UNIQUE ID, which
 will also be the same, given the same input.

 That is the ID I will use for looking up the offers on the market.
 Basically it's the Market ID, and the Offer just has the SAME ID,
 and that's how you match it up to the market.

 (This is analogous to how Transactions and Transaction Items have the
 same transaction number.)

 THIS MEANS that the user cannot simply set his minimum increment to
 a "divide-into equally" with the market minimum increment. Why not?
 Because since his number will be different from the next guy, they
 will calculate different IDs and thus end up on different markets.

 TODO: therefore the user MUST SUPPLY the EXACT SAME minimum increment
 of the market he wishes to trade on. There's no other way. However,
 I CAN allow the user to ALSO provide a second minimum, which must be
 a multiple of the first.

 TODO: Should add this same method to the Market object as well.


 To use OTOffer::GetIdentifier is simple:

 void blah (OTOffer& theOffer)
 {
    OTIdentifier MARKET_ID(theOffer); // the magic happens right here.

    // (Done.)
 }
 */
void OTOffer::GetIdentifier(Identifier& theIdentifier) const
{
    String strTemp, strAsset(GetInstrumentDefinitionID()),
        strCurrency(GetCurrencyID());

    int64_t lScale = GetScale();

    // In this way we generate a unique ID that will always be consistent
    // for the same instrument definition id, currency ID, and market scale.
    strTemp.Format(
        "ASSET TYPE:\n%s\nCURRENCY TYPE:\n%s\nMARKET SCALE:\n%" PRId64 "\n",
        strAsset.Get(), strCurrency.Get(), lScale);

    theIdentifier.CalculateDigest(strTemp);
}