Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	packages/frontend/src/components/networkStatus/index.js
  • Loading branch information
pshenmic committed Dec 19, 2024
2 parents 2a8ee52 + 3892955 commit 169938a
Show file tree
Hide file tree
Showing 66 changed files with 1,059 additions and 413 deletions.
64 changes: 54 additions & 10 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,55 @@ HTTP /status
hash: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
timestamp: "2024-06-06T21:50:20.949Z"
}
"epoch": {
"number": 3640,
"firstBlockHeight": 72534,
"firstCoreBlockHeight": 1160707,
"startTime": 1734457229495,
"feeMultiplier": 1,
"endTime": 1734460829495
},
"transactionsCount": 25912,
"totalCredits": 7288089799960610,
"totalCollectedFeesDay": 12733263640,
"transfersCount": 1849,
"dataContractsCount": 630,
"documentsCount": 15384,
"identitiesCount": 712,
"network": "dash-testnet-51",
"api": {
"version": "1.0.7",
"block": {
"height": 72555,
"hash": "EDA1CDF601224CD3ED168D35B4699DE2796F774B526103C64D371EF3AAFD8274",
"timestamp": "2024-12-17T17:57:08.758Z"
}
},
"tenderdash": {
"version": "1.4.0",
"block": {
"height": 72555,
"hash": "EDA1CDF601224CD3ED168D35B4699DE2796F774B526103C64D371EF3AAFD8274",
"timestamp": "2024-12-17T17:57:08.758Z"
}
},
"versions": {
"software": {
"dapi": "1.5.1",
"drive": "1.6.2",
"tenderdash": "1.4.0"
},
tenderdash: {
version: "0.14.0-dev.6",
block: {
height: 20154,
hash: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
timestamp: "2024-06-06T21:53:27.947Z"
}
}
"protocol": {
"tenderdash": {
"p2p": 10,
"block": 14
},
"drive": {
"latest": 6,
"current": 6
}
}
}
}
```
---
Expand Down Expand Up @@ -762,6 +802,9 @@ GET /identity/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec
"topUpsGasSpent": 46350660,
"withdrawalsGasSpent": 0,
"lastWithdrawalHash": null,
"lastWithdrawalTimestamp": null,
"totalTopUps": 0,
"totalWithdrawals": 0,
"publicKeys": [
{
"keyId": 0,
Expand Down Expand Up @@ -1034,8 +1077,9 @@ Response codes:
### Transfers by Identity
Return all transfers made by the given identity
* `limit` cannot be more then 100
* `type` cannot be less, then 0 and more then 8
```
GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transfers?page=1&limit=10&order=asc&type=1
GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transfers?hash=445E6F081DEE877867816AD3EF492E2C0BD1DDCCDC9C793B23DDDAF8AEA23118&page=1&limit=10&order=asc&type=6
{
pagination: {
Expand All @@ -1052,7 +1096,7 @@ GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transfers?page=1&li
txHash: "445E6F081DEE877867816AD3EF492E2C0BD1DDCCDC9C793B23DDDAF8AEA23118",
type: 6,
blockHash: "73171E0A8DCC10C6DA501E1C70A9C1E0BD6F1F8F834C2A1E787AF19B1F361D5E"
}, ...
}
]
}
```
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"lint": "standard ."
},
"dependencies": {
"@dashevo/wasm-dpp": "github:owl352/wasm-dpp",
"@dashevo/dapi-client": "github:owl352/dapi-client",
"@dashevo/dashd-rpc": "19.0.0",
"@dashevo/wasm-dpp": "github:owl352/wasm-dpp",
"@fastify/cors": "^8.3.0",
"@scure/base": "^1.1.5",
"bs58": "^6.0.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/api/src/DAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class DAPI {
}
})
}

async getStatus () {
return this.dapi.platform.getStatus()
}
}

module.exports = DAPI
13 changes: 10 additions & 3 deletions packages/api/src/controllers/IdentitiesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,16 @@ class IdentitiesController {

getTransfersByIdentity = async (request, response) => {
const { identifier } = request.params
const { page = 1, limit = 10, order = 'asc', type = undefined } = request.query

const transfers = await this.identitiesDAO.getTransfersByIdentity(identifier, Number(page ?? 1), Number(limit ?? 10), order, type)
const { page = 1, limit = 10, order = 'asc', type, hash } = request.query

const transfers = await this.identitiesDAO.getTransfersByIdentity(
identifier,
hash,
Number(page ?? 1),
Number(limit ?? 10),
order,
type
)

response.send(transfers)
}
Expand Down
26 changes: 22 additions & 4 deletions packages/api/src/controllers/MainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@ const { base58 } = require('@scure/base')
const API_VERSION = require('../../package.json').version

class MainController {
constructor (knex, dapi) {
constructor (knex, dapi, client) {
this.blocksDAO = new BlocksDAO(knex, dapi)
this.dataContractsDAO = new DataContractsDAO(knex)
this.documentsDAO = new DocumentsDAO(knex)
this.transactionsDAO = new TransactionsDAO(knex, dapi)
this.identitiesDAO = new IdentitiesDAO(knex, dapi)
this.identitiesDAO = new IdentitiesDAO(knex, dapi, client)
this.validatorsDAO = new ValidatorsDAO(knex)
this.dapi = dapi
}

getStatus = async (request, response) => {
const [blocks, stats, tdStatus, epochsInfo, totalCredits, totalCollectedFeesDay] = (await Promise.allSettled([
const [blocks, stats, status, tdStatus, epochsInfo, totalCredits, totalCollectedFeesDay] = (await Promise.allSettled([
this.blocksDAO.getBlocks(1, 1, 'desc'),
this.blocksDAO.getStats(),
this.dapi.getStatus(),
TenderdashRPC.getStatus(),
this.dapi.getEpochsInfo(1),
this.dapi.getTotalCredits(),
Expand Down Expand Up @@ -56,12 +57,29 @@ class MainController {
}
},
tenderdash: {
version: tdStatus?.version ?? null,
version: status?.version?.software.tenderdash ?? null,
block: {
height: tdStatus?.highestBlock?.height ?? null,
hash: tdStatus?.highestBlock?.hash ?? null,
timestamp: tdStatus?.highestBlock?.timestamp ?? null
}
},
versions: {
software: {
dapi: status?.version?.software.dapi ?? null,
drive: status?.version?.software.drive ?? null,
tenderdash: status?.version?.software.tenderdash ?? null
},
protocol: {
tenderdash: {
p2p: status?.version?.protocol.tenderdash?.p2p ?? null,
block: status?.version?.protocol.tenderdash?.block ?? null
},
drive: {
latest: status?.version?.protocol.drive?.latest ?? null,
current: status?.version?.protocol.drive?.current ?? null
}
}
}
})
}
Expand Down
50 changes: 38 additions & 12 deletions packages/api/src/dao/IdentitiesDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ module.exports = class IdentitiesDAO {
.from('with_alias')
.limit(1)

const statisticSubquery = this.knex('state_transitions')
.whereRaw(`owner = identifier and type=${IDENTITY_CREDIT_WITHDRAWAL}`)
.as('statistic')

const rows = await this.knex.with('with_alias', mainQuery)
.select(
'identifier', 'owner', 'revision',
Expand All @@ -91,13 +95,28 @@ module.exports = class IdentitiesDAO {
.where('owner', identifier)
.andWhere('type', IDENTITY_CREDIT_WITHDRAWAL)
.as('withdrawals_gas_spent'))
.select(this.knex('state_transitions')
.select(this.knex(statisticSubquery)
.select('hash')
.where('owner', identifier)
.andWhere('type', IDENTITY_CREDIT_WITHDRAWAL)
.where('type', IDENTITY_CREDIT_WITHDRAWAL)
.orderBy('id', 'desc')
.limit(1)
.as('last_withdrawal_hash'))
.select(this.knex(statisticSubquery)
.select('timestamp')
.where('type', IDENTITY_CREDIT_WITHDRAWAL)
.orderBy('id', 'desc')
.limit(1)
.as('last_withdrawal_timestamp'))
.select(
this.knex(statisticSubquery)
.count('id')
.whereRaw(`type=${IDENTITY_CREDIT_WITHDRAWAL}`)
.as('total_withdrawals'))
.select(
this.knex(statisticSubquery)
.count('id')
.whereRaw(`type=${IDENTITY_TOP_UP}`)
.as('total_top_ups'))
.from('with_alias')

if (!rows.length) {
Expand Down Expand Up @@ -125,7 +144,7 @@ module.exports = class IdentitiesDAO {
if (row.tx_data) {
const { assetLockProof } = await decodeStateTransition(this.client, row.tx_data)

fundingCoreTx = assetLockProof?.txid
fundingCoreTx = assetLockProof?.fundingCoreTx
}

return Identity.fromObject({
Expand Down Expand Up @@ -356,32 +375,39 @@ module.exports = class IdentitiesDAO {
return new PaginatedResultSet(rows.map(row => Transaction.fromRow(row)), page, limit, totalCount)
}

getTransfersByIdentity = async (identifier, page, limit, order, type) => {
getTransfersByIdentity = async (identifier, hash, page, limit, order, type) => {
const fromRank = (page - 1) * limit + 1
const toRank = fromRank + limit - 1

let searchQuery = `(transfers.sender = '${identifier}' OR transfers.recipient = '${identifier}')`

if (typeof type === 'number') {
searchQuery = searchQuery + ` AND state_transitions.type = ${type}`
}

if (hash) {
searchQuery = searchQuery + ` AND state_transitions.hash = '${hash}'`
}

const subquery = this.knex('transfers')
.select(
'transfers.id as id', 'transfers.amount as amount',
'transfers.sender as sender', 'transfers.recipient as recipient',
'transfers.state_transition_hash as tx_hash',
'state_transitions.block_hash as block_hash',
'state_transitions.type as type'
'state_transitions.type as type',
'state_transitions.gas_used as gas_used'
)
.select(this.knex.raw(`rank() over (order by transfers.id ${order}) rank`))
.whereRaw(`(transfers.sender = '${identifier}' OR transfers.recipient = '${identifier}') ${
typeof type === 'number'
? `AND state_transitions.type = ${type}`
: ''
}`)
.whereRaw(searchQuery)
.leftJoin('state_transitions', 'state_transitions.hash', 'transfers.state_transition_hash')

const rows = await this.knex.with('with_alias', subquery)
.select(
'rank', 'amount', 'block_hash', 'type',
'sender', 'recipient', 'with_alias.id',
'tx_hash', 'blocks.timestamp as timestamp',
'block_hash'
'block_hash', 'gas_used'
)
.select(this.knex('with_alias').count('*').as('total_count'))
.leftJoin('blocks', 'blocks.hash', 'with_alias.block_hash')
Expand Down
24 changes: 20 additions & 4 deletions packages/api/src/models/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = class Identity {
lastWithdrawalHash
publicKeys
fundingCoreTx
totalTopUps
totalWithdrawals
lastWithdrawalTimestamp

constructor (
identifier, owner, revision,
Expand All @@ -25,7 +28,9 @@ module.exports = class Identity {
totalTransfers, txHash, isSystem,
aliases, totalGasSpent, averageGasSpent,
topUpsGasSpent, withdrawalsGasSpent,
lastWithdrawalHash, publicKeys, fundingCoreTx
lastWithdrawalHash, lastWithdrawalTimestamp,
totalTopUps, totalWithdrawals, publicKeys,
fundingCoreTx
) {
this.identifier = identifier ? identifier.trim() : null
this.owner = owner ? owner.trim() : null
Expand All @@ -46,6 +51,9 @@ module.exports = class Identity {
this.lastWithdrawalHash = lastWithdrawalHash ?? null
this.publicKeys = publicKeys ?? []
this.fundingCoreTx = fundingCoreTx ?? null
this.totalTopUps = totalTopUps ?? null
this.totalWithdrawals = totalWithdrawals ?? null
this.lastWithdrawalTimestamp = lastWithdrawalTimestamp ?? null
}

static fromObject ({
Expand All @@ -55,7 +63,8 @@ module.exports = class Identity {
totalTransfers, txHash, isSystem,
aliases, totalGasSpent, averageGasSpent,
topUpsGasSpent, withdrawalsGasSpent,
lastWithdrawalHash, publicKeys, fundingCoreTx
lastWithdrawalHash, publicKeys, fundingCoreTx,
totalTopUps, totalWithdrawals, lastWithdrawalTimestamp
}) {
return new Identity(
identifier,
Expand All @@ -75,6 +84,9 @@ module.exports = class Identity {
topUpsGasSpent,
withdrawalsGasSpent,
lastWithdrawalHash,
lastWithdrawalTimestamp,
totalTopUps,
totalWithdrawals,
publicKeys,
fundingCoreTx
)
Expand All @@ -88,7 +100,8 @@ module.exports = class Identity {
total_transfers, tx_hash, is_system,
aliases, total_gas_spent, average_gas_spent,
top_ups_gas_spent, withdrawals_gas_spent,
last_withdrawal_hash
last_withdrawal_hash, last_withdrawal_timestamp,
total_top_ups, total_withdrawals
}) {
return new Identity(
identifier?.trim(),
Expand All @@ -107,7 +120,10 @@ module.exports = class Identity {
Number(average_gas_spent),
Number(top_ups_gas_spent),
Number(withdrawals_gas_spent),
last_withdrawal_hash
last_withdrawal_hash,
last_withdrawal_timestamp,
Number(total_top_ups),
Number(total_withdrawals)
)
}
}
8 changes: 5 additions & 3 deletions packages/api/src/models/Transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ module.exports = class Transfer {
txHash
type
blockHash
gasUsed

constructor (amount, sender, recipient, timestamp, txHash, type, blockHash) {
constructor (amount, sender, recipient, timestamp, txHash, type, blockHash, gasUsed) {
this.amount = amount ?? null
this.sender = sender ? sender.trim() : null
this.recipient = recipient ? recipient.trim() : null
this.timestamp = timestamp ?? null
this.txHash = txHash ?? null
this.type = type ?? null
this.blockHash = blockHash ?? null
this.gasUsed = gasUsed ?? null
}

// eslint-disable-next-line camelcase
static fromRow ({ amount, sender, recipient, timestamp, tx_hash, type, block_hash }) {
return new Transfer(parseInt(amount), sender, recipient, timestamp, tx_hash, type, block_hash)
static fromRow ({ amount, sender, recipient, timestamp, tx_hash, type, block_hash, gas_used }) {
return new Transfer(parseInt(amount), sender, recipient, timestamp, tx_hash, type, block_hash, Number(gas_used))
}
}
Loading

0 comments on commit 169938a

Please sign in to comment.