Last active
August 1, 2023 20:06
-
-
Save shortthefomo/bb9c92ee20452ec2efcb571e7fd9fbf4 to your computer and use it in GitHub Desktop.
URIToken hook
This file contains hidden or 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
#include "hookapi.h" | |
#define MIN_XRP_AMOUNT 100000000 // 100 XRP in drops | |
#define ISSUER_ACCOUNT "rL4usRexjgCPTG8RoZvVHXmUjuYdWbRx2T" | |
#define MY_ACCOUNT "rL4usRexjgCPTG8RoZvVHXmUjuYdWbRx2T" | |
int64_t hook(uint32_t reserved) { | |
TRACESTR("HookOnURITokenCreateSellOffer: Start."); | |
// Filter on outgoing transactions | |
unsigned char account_buffer[20]; | |
int64_t account_len = otxn_field(SBUF(account_buffer), sfAccount); | |
if (account_len != 20) { | |
rollback(SBUF("HookOnURITokenCreateSellOffer: Could not get account."), 1); | |
} | |
if (!BUFFER_EQUAL_20(account_buffer, MY_ACCOUNT)) { | |
DONE("HookOnURITokenCreateSellOffer: Ignoring non-outgoing transaction."); | |
} | |
// Filter on sfAmount | |
unsigned char amount_buffer[SFS_AMOUNT_IOU]; | |
int64_t amount_len = otxn_field(SBUF(amount_buffer), sfAmount); | |
if (amount_len != 8) { | |
DONE("HookOnURITokenCreateSellOffer: Ignoring non-XRP transaction."); | |
} | |
int64_t amount_drops = AMOUNT_TO_DROPS(amount_buffer); | |
if (amount_drops < MIN_XRP_AMOUNT) { | |
// Check if the NFT was issued from the specified wallet | |
unsigned char issuer_buffer[20]; | |
int64_t issuer_len = otxn_field(SBUF(issuer_buffer), sfIssuer); | |
if (issuer_len != 20) { | |
rollback(SBUF("HookOnURITokenCreateSellOffer: Could not get issuer."), 1); | |
} | |
if (!BUFFER_EQUAL_20(issuer_buffer, ISSUER_ACCOUNT)) { | |
rollback(SBUF("HookOnURITokenCreateSellOffer: sfAmount of Sell tx is less than 100 XRP and NFT was not issued from the specified wallet."), 1); | |
} | |
} | |
TRACESTR("HookOnURITokenCreateSellOffer: End."); | |
accept(SBUF("HookOnURITokenCreateSellOffer: Finished."), __LINE__); | |
_g(1,1); | |
// unreachable | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment