Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split MetaDEx RPC commands and payload creation #51

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions src/omnicore/convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ void swapByteOrder16(uint16_t&);
void swapByteOrder32(uint32_t&);
void swapByteOrder64(uint64_t&);

/**
* Pushes bytes to the end of a vector.
*/
#define PUSH_BACK_BYTES(vector, value)\
vector.insert(vector.end(), reinterpret_cast<unsigned char *>(&(value)),\
reinterpret_cast<unsigned char *>(&(value)) + sizeof((value)));

/**
* Pushes bytes to the end of a vector based on a pointer.
*/
#define PUSH_BACK_BYTES_PTR(vector, ptr, size)\
vector.insert(vector.end(), reinterpret_cast<unsigned char *>((ptr)),\
reinterpret_cast<unsigned char *>((ptr)) + (size));
}


Expand Down
106 changes: 105 additions & 1 deletion src/omnicore/createpayload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@
#include <string>
#include <vector>

/**
* Pushes bytes to the end of a vector.
*/
#define PUSH_BACK_BYTES(vector, value)\
vector.insert(vector.end(), reinterpret_cast<unsigned char *>(&(value)),\
reinterpret_cast<unsigned char *>(&(value)) + sizeof((value)));

/**
* Pushes bytes to the end of a vector based on a pointer.
*/
#define PUSH_BACK_BYTES_PTR(vector, ptr, size)\
vector.insert(vector.end(), reinterpret_cast<unsigned char *>((ptr)),\
reinterpret_cast<unsigned char *>((ptr)) + (size));


std::vector<unsigned char> CreatePayload_SimpleSend(uint32_t propertyId, uint64_t amount)
{
std::vector<unsigned char> payload;
Expand Down Expand Up @@ -277,16 +292,103 @@ std::vector<unsigned char> CreatePayload_ChangeIssuer(uint32_t propertyId)
return payload;
}

std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired, uint8_t action)
std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired)
{
std::vector<unsigned char> payload;

uint16_t messageType = 21;
uint16_t messageVer = 0;
uint8_t action = 1; // ADD

mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder32(propertyIdForSale);
mastercore::swapByteOrder64(amountForSale);
mastercore::swapByteOrder32(propertyIdDesired);
mastercore::swapByteOrder64(amountDesired);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyIdForSale);
PUSH_BACK_BYTES(payload, amountForSale);
PUSH_BACK_BYTES(payload, propertyIdDesired);
PUSH_BACK_BYTES(payload, amountDesired);
PUSH_BACK_BYTES(payload, action);

return payload;
}

std::vector<unsigned char> CreatePayload_MetaDExCancelPrice(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired)
{
std::vector<unsigned char> payload;

uint16_t messageType = 21;
uint16_t messageVer = 0;
uint8_t action = 2; // CANCEL_AT_PRICE

mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder32(propertyIdForSale);
mastercore::swapByteOrder64(amountForSale);
mastercore::swapByteOrder32(propertyIdDesired);
mastercore::swapByteOrder64(amountDesired);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyIdForSale);
PUSH_BACK_BYTES(payload, amountForSale);
PUSH_BACK_BYTES(payload, propertyIdDesired);
PUSH_BACK_BYTES(payload, amountDesired);
PUSH_BACK_BYTES(payload, action);

return payload;
}

std::vector<unsigned char> CreatePayload_MetaDExCancelPair(uint32_t propertyIdForSale, uint32_t propertyIdDesired)
{
std::vector<unsigned char> payload;

uint16_t messageType = 21;
uint16_t messageVer = 0;
uint64_t amountForSale = 0;
uint64_t amountDesired = 0;
uint8_t action = 3; // CANCEL_ALL_FOR_PAIR

mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder32(propertyIdForSale);
mastercore::swapByteOrder64(amountForSale);
mastercore::swapByteOrder32(propertyIdDesired);
mastercore::swapByteOrder64(amountDesired);

PUSH_BACK_BYTES(payload, messageVer);
PUSH_BACK_BYTES(payload, messageType);
PUSH_BACK_BYTES(payload, propertyIdForSale);
PUSH_BACK_BYTES(payload, amountForSale);
PUSH_BACK_BYTES(payload, propertyIdDesired);
PUSH_BACK_BYTES(payload, amountDesired);
PUSH_BACK_BYTES(payload, action);

return payload;
}

std::vector<unsigned char> CreatePayload_MetaDExCancelEcosystem(uint8_t ecosystem)
{
std::vector<unsigned char> payload;

uint16_t messageType = 21;
uint16_t messageVer = 0;
uint32_t propertyIdForSale = ecosystem;
uint64_t amountForSale = 0;
uint32_t propertyIdDesired = ecosystem;
uint64_t amountDesired = 0;
uint8_t action = 4; // CANCEL_EVERYTHING

mastercore::swapByteOrder16(messageVer);
mastercore::swapByteOrder16(messageType);
mastercore::swapByteOrder32(propertyIdForSale);
mastercore::swapByteOrder64(amountForSale);
mastercore::swapByteOrder32(propertyIdDesired);
mastercore::swapByteOrder64(amountDesired);

PUSH_BACK_BYTES(payload, messageVer);
Expand All @@ -300,4 +402,6 @@ std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale
return payload;
}

#undef PUSH_BACK_BYTES
#undef PUSH_BACK_BYTES_PTR

5 changes: 4 additions & 1 deletion src/omnicore/createpayload.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ std::vector<unsigned char> CreatePayload_CloseCrowdsale(uint32_t propertyId);
std::vector<unsigned char> CreatePayload_Grant(uint32_t propertyId, uint64_t amount, std::string memo);
std::vector<unsigned char> CreatePayload_Revoke(uint32_t propertyId, uint64_t amount, std::string memo);
std::vector<unsigned char> CreatePayload_ChangeIssuer(uint32_t propertyId);
std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired, uint8_t action);
std::vector<unsigned char> CreatePayload_MetaDExTrade(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired);
std::vector<unsigned char> CreatePayload_MetaDExCancelPrice(uint32_t propertyIdForSale, uint64_t amountForSale, uint32_t propertyIdDesired, uint64_t amountDesired);
std::vector<unsigned char> CreatePayload_MetaDExCancelPair(uint32_t propertyIdForSale, uint32_t propertyIdDesired);
std::vector<unsigned char> CreatePayload_MetaDExCancelEcosystem(uint8_t ecosystem);


#endif // OMNICORE_CREATEPAYLOAD_H
Loading