Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
4 changes: 2 additions & 2 deletions packages/api-mongodb-plugin/src/api/get_smart_contracts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AccountsModel from '../models/account';

const get_smart_contracts = async (query: { records_count: string }) => {
const get_smart_contracts = async (query: { records_count: number }) => {
try{
let { records_count } = query;
let result: object;
Expand All @@ -12,7 +12,7 @@ const get_smart_contracts = async (query: { records_count: string }) => {
query_gen.sort({_id: -1});

(records_count !== undefined) ?
query_gen.limit(parseInt(records_count)): query_gen.limit(100);
query_gen.limit(records_count): query_gen.limit(100);

result = await query_gen.exec();
return result;
Expand Down
19 changes: 0 additions & 19 deletions packages/api-postgres-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ Get the list of actions based on certain criteria:
* `account_name` - string - if this value is passed then it fetches latest 100 transactions for smart contract `account_name`
* `records_count` - string - Number of actions to fetch (default is 100)

### `get_all_permissions`

Get the list of all last permissions based on the number of `records_count` to show.

* `records_count` - string
* `account_name` - if this is passed then fetches the permission for only that `account_name`

### `get_block_details`

Get the details of the block based on its ID or number as indicated by `id_or_num` and RPC `endpoint` to fetch action payload.
Expand All @@ -41,18 +34,6 @@ Get the list of blocks based on certain criteria:
* `show_empty` - string - Whether to show empty blocks or not
* `records_count` - string - Number of blocks to show

### get_permissions_by_public_key

Get the list of permissions based on its public_key

* `public_key` - string

### `get_smart_contracts`

Get the list of all available smart contracts based on the number of `records_count` to show.

* `records_count` - string

### `get_transaction_details`

Get the details for a particular transaction based on its `id` and RPC `endpoint` to fetch action payload.
Expand Down
24 changes: 12 additions & 12 deletions packages/api-postgres-plugin/api/get_action_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ const get_action_details = async (query) => {
let result = [];
let { id, action_ordinal, endpoint, block_num } = query;
id = id.toUpperCase();

let query_gen = `
SELECT * FROM chain.action_trace
WHERE transaction_id = '${id}' AND action_ordinal = ${action_ordinal} ${(block_num !== undefined) ? `AND block_num = '${block_num}'` : ''}`;

let promise = new Promise((resolve, reject)=>{
db.query(query_gen, "", (err, result) => {
if (err) {
console.error('Error executing get action details query:: ', err.stack);
resolve([]);
}else{
resolve(result.rows);
}
}else{
resolve(result.rows);
}
})
})
})
let resultObj = await promise;
if(resultObj.length > 0 && resultObj[0].hasOwnProperty("transaction_id")){

if(resultObj.length > 0 && resultObj[0].hasOwnProperty("transaction_id")){
// Delete serialized act data from response
delete resultObj[0].act_data;
// delete resultObj[0].act_data;
// Fetch action data from blockchain
let blockDetailsRpcRes = await apiRpc["get_block"]({endpoint: endpoint, id_or_num: resultObj[0].block_num});
let transaction = blockDetailsRpcRes.transactions.filter(eachTrx => (eachTrx.trx.id !== undefined ? eachTrx.trx.id.toUpperCase() : eachTrx.id) === resultObj[0].transaction_id);
Expand All @@ -36,9 +36,9 @@ const get_action_details = async (query) => {
});
}else{
result = resultObj;
}
return result;
}

return result;

}catch(err){
console.log("caught exception ", err)
Expand Down
4 changes: 2 additions & 2 deletions packages/api-postgres-plugin/api/get_action_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const get_action_history = async query => {
const statement = `
${account_name !== undefined
? `
SELECT transaction_id, action_ordinal, act_account, act_name, act_data, timestamp, block_num, actor, permission
SELECT transaction_id, action_ordinal, act_account, act_name, timestamp, block_num, actor, permission
FROM chain.action_trace
WHERE creator_action_ordinal = 0 AND act_account = ANY('{${account_name}}')
`
Expand All @@ -16,7 +16,7 @@ const get_action_history = async query => {
${account_name !== undefined && actor_name !== undefined ? `UNION` : ``}
${actor_name !== undefined
? `
SELECT transaction_id, action_ordinal, act_account, act_name, act_data, timestamp, block_num, actor, permission
SELECT transaction_id, action_ordinal, act_account, act_name, timestamp, block_num, actor, permission
FROM chain.action_trace
WHERE creator_action_ordinal = 0 AND actor = ANY('{${actor_name}}')
`
Expand Down
4 changes: 2 additions & 2 deletions packages/api-postgres-plugin/api/get_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const get_actions = async query => {
const { account_name, records_count } = query;
const limit = Math.min(parseInt(records_count) || 100, 100);
const statement = `
SELECT transaction_id, action_ordinal, act_account, act_name, act_data, timestamp, block_num, actor, permission
SELECT transaction_id, action_ordinal, act_account, act_name, timestamp, block_num, actor, permission
FROM chain.action_trace
WHERE
creator_action_ordinal = 0
${account_name !== undefined ? `AND act_account = '${account_name}'` : ''}
${account_name !== undefined ? `AND act_account = '${account_name}'` : ''}
ORDER BY block_num DESC
LIMIT ${limit}
`;
Expand Down
80 changes: 68 additions & 12 deletions packages/api-postgres-plugin/api/get_actions_with_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const get_actions_with_filter = async query => {
show_data_size = 'false'
} = query;
const limit = Math.min(parseInt(page_size) || 100, 100);
const table = `
var table = `
chain.action_trace
WHERE
${action_filter !== undefined && account_name !== undefined
? action_filter === 'contract' ? `creator_action_ordinal = 0 AND act_account = '${account_name}'` :
action_filter === 'signed' ? `creator_action_ordinal = 0 AND actor = '${account_name}'` :
action_filter === 'received' ? `receiver = 'eosio.token' AND act_account = 'eosio.token' AND act_name = 'transfer' AND token_to = '${account_name}'` :
action_filter === 'sent' ? `receiver = 'eosio.token' AND act_account = 'eosio.token' AND act_name = 'transfer' AND token_from = '${account_name}'` :
? action_filter === 'contract' ? `creator_action_ordinal = 0 AND act_account = '${account_name}'` :
action_filter === 'signed' ? `creator_action_ordinal = 0 AND actor = '${account_name}'` :
// action_filter === 'received' ? `receiver = 'eosio.token' AND act_account = 'eosio.token' AND act_name = 'transfer' AND token_to = '${account_name}'` :
// action_filter === 'sent' ? `receiver = 'eosio.token' AND act_account = 'eosio.token' AND act_name = 'transfer' AND token_from = '${account_name}'` :
'transaction_id IS NOT NULL'
: 'transaction_id IS NOT NULL'}
${max_rgs !== undefined
Expand All @@ -33,27 +33,83 @@ const get_actions_with_filter = async query => {
}
`;

const statement = `
let statement = `
SELECT
transaction_id AS id,
block_num,
timestamp,
act_account,
act_name,
actor,
receipt_global_sequence,
token_to,
token_from,
amount,
symbol
receipt_global_sequence
FROM
${table}
ORDER BY
receipt_global_sequence ${direction === 'next' ? 'DESC' : 'ASC'}
LIMIT ${limit}
`;

const count_statement = `SELECT COUNT(transaction_id) AS count FROM ${table}`;
let count_statement = `SELECT COUNT(transaction_id) AS count FROM ${table}`;


if(action_filter === 'received'){
statement = `
SELECT
chain.transfer_t.transaction_id AS id,
chain.transfer_t.block_num AS block_num,
chain.transfer_t.timestamp AS timestamp,
chain.action_trace.receiver AS receiver,
chain.action_trace.act_account AS act_account,
chain.action_trace.act_name AS act_name,
chain.action_trace.actor AS actor,
chain.action_trace.receipt_global_sequence AS receipt_global_sequence,
chain.transfer_t.token_to AS token_to,
chain.transfer_t.token_from AS token_from,
chain.transfer_t.quantity_amount as amount,
chain.transfer_t.quantity_symbol as symbol
FROM chain.transfer_t
INNER JOIN chain.action_trace ON chain.action_trace.transaction_id = chain.transfer_t.transaction_id AND chain.action_trace.action_ordinal = chain.transfer_t.action_ordinal
WHERE
receiver = 'eosio.token' AND act_account = 'eosio.token' AND act_name = 'transfer' AND actor != 'eosio' AND token_to = '${account_name}'
ORDER BY
chain.action_trace.receipt_global_sequence ${direction === 'next' ? 'DESC' : 'ASC'}
LIMIT ${limit}
`

count_statement = `SELECT COUNT(transaction_id) AS count FROM chain.transfer_t WHERE token_to = '${account_name}'`
}


if(action_filter === 'sent'){
statement = `
SELECT
chain.transfer_t.transaction_id AS id,
chain.transfer_t.block_num AS block_num,
chain.transfer_t.timestamp AS timestamp,
chain.action_trace.receiver AS receiver,
chain.action_trace.act_account AS act_account,
chain.action_trace.act_name AS act_name,
chain.action_trace.actor AS actor,
chain.action_trace.receipt_global_sequence AS receipt_global_sequence,
chain.transfer_t.token_to AS token_to,
chain.transfer_t.token_from AS token_from,
chain.transfer_t.quantity_amount as amount,
chain.transfer_t.quantity_symbol as symbol
FROM chain.transfer_t
INNER JOIN chain.action_trace ON chain.action_trace.transaction_id = chain.transfer_t.transaction_id AND chain.action_trace.action_ordinal = chain.transfer_t.action_ordinal
WHERE
receiver = 'eosio.token' AND act_account = 'eosio.token' AND act_name = 'transfer' AND actor != 'eosio' AND token_from = '${account_name}'
ORDER BY
chain.action_trace.receipt_global_sequence ${direction === 'next' ? 'DESC' : 'ASC'}
LIMIT ${limit}
`

count_statement = `SELECT COUNT(transaction_id) AS count FROM chain.transfer_t WHERE token_from = '${account_name}'`
}



console.log(statement)

try {
const data = (await db.queryAsync(statement, '')).rows;
Expand Down
35 changes: 0 additions & 35 deletions packages/api-postgres-plugin/api/get_all_permissions.js

This file was deleted.

4 changes: 2 additions & 2 deletions packages/api-postgres-plugin/api/get_blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const get_blocks = async query => {
FROM chain.block_info
`
: `
SELECT *
FROM chain.received_nonempty_block
SELECT block_id, block_num, timestamp, transaction_count, producer
FROM chain.block_info where transaction_count != 0
`
}
ORDER BY block_num DESC
Expand Down
24 changes: 0 additions & 24 deletions packages/api-postgres-plugin/api/get_permission_link.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/api-postgres-plugin/api/get_permissions_by_public_key.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/api-postgres-plugin/api/get_smart_contracts.js

This file was deleted.

4 changes: 1 addition & 3 deletions packages/api-postgres-plugin/api/get_transaction_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const get_transaction_details = async (query) => {
id = id.toUpperCase();
let result = [];
let query_gen = `
SELECT tt.*,
(SELECT ata.actor FROM chain.action_trace_authorization ata WHERE ata.block_num = tt.block_num AND ata.transaction_id = tt.id AND ata.action_ordinal=1 LIMIT 1),
(SELECT ata.permission FROM chain.action_trace_authorization ata WHERE ata.block_num = tt.block_num AND ata.transaction_id = tt.id AND ata.action_ordinal=1 LIMIT 1)
SELECT tt.*
FROM chain.transaction_trace as tt
WHERE id = '${id}'`;

Expand Down
2 changes: 1 addition & 1 deletion packages/api-postgres-plugin/api/get_transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const get_transactions = async query => {
const { records_count } = query;
const limit = Math.min(parseInt(records_count) || 100, 100);
const statement = `
SELECT id, block_num, partial_expiration, status
SELECT id, block_num, transaction_expiration, status
FROM chain.transaction_trace
ORDER BY block_num DESC, transaction_ordinal DESC
LIMIT ${limit}
Expand Down
2 changes: 1 addition & 1 deletion packages/api-postgres-plugin/api/get_trx_action_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const get_trx_action_list = async query => {
const limit = Math.min(parseInt(records_count) || 100, 100);
const statement = `
SELECT transaction_id AS id, block_num, timestamp, act_account, act_name, action_ordinal
FROM chain.action_trace
FROM chain.action_trace
WHERE creator_action_ordinal = 0 ${account_name !== undefined ? `AND act_account = '${account_name}'` : ''}
ORDER BY block_num DESC
LIMIT ${limit}
Expand Down
Loading