Skip to content

Commit

Permalink
add support for MEMO in MINT action
Browse files Browse the repository at this point in the history
  • Loading branch information
jdogresorg committed May 22, 2024
1 parent 34bd107 commit b2716f5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/actions/MINT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ This command mints `BTNS` `token` supply
| `TICK` | String | 1 to 250 characters in length |
| `AMOUNT` | String | Amount of `tokens` to mint |
| `DESTINATION` | String | Address to transfer minted `tokens` to |
| `MEMO` | String | An optional memo to include |

## Formats

### Version `0`
- `VERSION|TICK|AMOUNT|DESTINATION`
- `VERSION|TICK|AMOUNT|DESTINATION|MEMO`

## Examples
```
Expand Down
10 changes: 9 additions & 1 deletion indexer/includes/actions/mint.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function btnsMint($params=null, $data=null, $error=null){

// Define list of known FORMATS
$formats = array(
0 => 'VERSION|TICK|AMOUNT|DESTINATION'
0 => 'VERSION|TICK|AMOUNT|DESTINATION|MEMO'
);

/*****************************************************************
Expand Down Expand Up @@ -91,6 +91,14 @@ function btnsMint($params=null, $data=null, $error=null){
* General Validations
****************************************************************/

// Verify no pipe in MEMO (BTNS uses pipe as field delimiter)
if(!$error && isset($data->MEMO) && strpos($data->MEMO,'|')!==false)
$error = 'invalid: MEMO (pipe)';

// Verify no semicolon in MEMO (BTNS uses semicolon as action delimiter)
if(!$error && isset($data->MEMO) && strpos($data->MEMO,';')!==false)
$error = 'invalid: MEMO (semicolon)';

// Verify AMOUNT is less than MAX_MINT
if(!$error && isset($data->AMOUNT) && $data->AMOUNT > $data->MAX_MINT)
$error = 'invalid: AMOUNT > MAX_MINT';
Expand Down
4 changes: 3 additions & 1 deletion indexer/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ function createMint( $data=null ){
$source_id = createAddress($data->SOURCE);
$destination_id = createAddress($data->DESTINATION);
$tx_hash_id = createTransaction($data->TX_HASH);
$memo_id = createMemo($data->MEMO);
$status_id = createStatus($data->STATUS);
$tx_index = $mysqli->real_escape_string($data->TX_INDEX);
$amount = $mysqli->real_escape_string($data->AMOUNT);
Expand All @@ -340,12 +341,13 @@ function createMint( $data=null ){
source_id='{$source_id}',
block_index='{$block_index}',
tx_index='{$tx_index}',
memo_id='{$memo_id}',
status_id='{$status_id}'
WHERE
tx_hash_id='{$tx_hash_id}'";
} else {
// INSERT record
$sql = "INSERT INTO mints (tx_index, tick_id, amount, source_id, destination_id, tx_hash_id, block_index, status_id) values ('{$tx_index}','{$tick_id}', '{$amount}', '{$source_id}', '{$destination_id}', '{$tx_hash_id}', '{$block_index}', '{$status_id}')";
$sql = "INSERT INTO mints (tx_index, tick_id, amount, source_id, destination_id, tx_hash_id, block_index, memo_id, status_id) values ('{$tx_index}','{$tick_id}', '{$amount}', '{$source_id}', '{$destination_id}', '{$tx_hash_id}', '{$block_index}', '{$memo_id}', '{$status_id}')";
}
$results = $mysqli->query($sql);
if(!$results)
Expand Down
2 changes: 2 additions & 0 deletions indexer/sql/mints.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CREATE TABLE mints (
destination_id INTEGER UNSIGNED, -- id of record in index_addresses table (optional, mint and transfer)
tx_hash_id INTEGER UNSIGNED, -- id of record in index_transactions
block_index INTEGER UNSIGNED, -- block index of MINT transaction
memo_id INTEGER UNSIGNED, -- id of record in index_memos table
status_id INTEGER UNSIGNED -- id of record in index_statuses table
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Expand All @@ -15,4 +16,5 @@ CREATE INDEX tick_id ON mints (tick_id);
CREATE INDEX tx_hash_id ON mints (tx_hash_id);
CREATE INDEX source_id ON mints (source_id);
CREATE INDEX destination_id ON mints (destination_id);
CREATE INDEX memo_id ON mints (memo_id);
CREATE INDEX status_id ON mints (status_id);

0 comments on commit b2716f5

Please sign in to comment.