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

Aliases with ContestedResourceVoteState #306

Merged
merged 38 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d1e7b1d
work work work
owl352 Oct 31, 2024
8b80096
lint and fixes
owl352 Oct 31, 2024
a2ce9ea
update package.json
owl352 Nov 1, 2024
f00f3b5
main controller tests update
owl352 Nov 1, 2024
8c6d092
fix
owl352 Nov 1, 2024
4fd87d9
initial commit
owl352 Nov 7, 2024
3125028
search and txs by identity fix
owl352 Nov 7, 2024
2b5d84e
trim
owl352 Nov 7, 2024
d366c6d
trim
owl352 Nov 7, 2024
6045231
lint
owl352 Nov 7, 2024
43b1a77
Merge branch 'refs/heads/feat/contested' into feat/transactions-owners
owl352 Nov 8, 2024
afb8a44
added aliases
owl352 Nov 8, 2024
42b93aa
README.md update
owl352 Nov 8, 2024
10b1d22
tiny fixes
owl352 Nov 8, 2024
3a093b7
Merge branch 'master' into feat/transactions-owners
owl352 Nov 17, 2024
e579d4b
fixes
owl352 Nov 17, 2024
664ba7e
Update packages/api/src/controllers/MainController.js
owl352 Nov 17, 2024
bffe9d7
fix
owl352 Nov 17, 2024
83d0c86
env update
owl352 Nov 17, 2024
ada63df
env update
owl352 Nov 17, 2024
3f9830c
fixes
owl352 Nov 17, 2024
07ac06f
fixes
owl352 Nov 17, 2024
e274930
Merge remote-tracking branch 'origin/feat/transactions-owners' into f…
owl352 Nov 17, 2024
5cc5842
test fix
owl352 Nov 17, 2024
2fee3fe
fixes
owl352 Nov 17, 2024
f673d56
`README.md` update
owl352 Nov 17, 2024
3cf5b5f
`identities.spec.js` update
owl352 Nov 17, 2024
ed320b9
`identities.spec.js` and `main.spec.js` updates
owl352 Nov 17, 2024
90bd4d5
`main.spec.js` update
owl352 Nov 17, 2024
85f198b
fixes
owl352 Nov 17, 2024
5d2e965
`IdentitiesDAO.js` fix
owl352 Nov 17, 2024
a18d88a
main tests fix
owl352 Nov 17, 2024
3fe5ae1
transactions.spec.js fix
owl352 Nov 17, 2024
91b11b2
tiny fixes
owl352 Nov 17, 2024
0c9d0ba
tiny fixes
owl352 Nov 17, 2024
9ab1634
names fix
owl352 Nov 17, 2024
af1b376
structure fix
owl352 Nov 17, 2024
9ec6a53
name fix
owl352 Nov 17, 2024
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
81 changes: 50 additions & 31 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,16 @@ GET /transaction/DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEE
type: 0,
gasUsed: 1337000,
status: "SUCCESS",
error: null
error: null,
owner: {
identifier: "6q9RFbeea73tE31LGMBLFZhtBUX3wZL3TcNynqE18Zgs",
aliases: [
{
alias: "alias.dash",
status: "locked"
}
]
}
}
```

Expand Down Expand Up @@ -450,7 +459,16 @@ GET /transactions?=1&limit=10&order=asc
type: 0,
gasUsed: 1337000,
status: "SUCCESS",
error: null
error: null,
owner: {
identifier: "6q9RFbeea73tE31LGMBLFZhtBUX3wZL3TcNynqE18Zgs",
aliases: [
{
alias: "alias.dash",
status: "locked"
}
]
}
}, ...
]
}
Expand Down Expand Up @@ -599,7 +617,12 @@ GET /identity/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false,
aliases: ["test.dash"...]
aliases: [
{
alias: "alias.dash",
status: "locked"
}
]
}
```
Response codes:
Expand All @@ -612,21 +635,11 @@ Response codes:
### Identity by DPNS
Return identity by given DPNS/alias
```
GET /dpns/identity?dpns=test-name.1.dash
GET /dpns/identity?dpns=canuseethat2.dash

{
identifier: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
owner: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
revision: 1,
balance: 1000000,
timestamp: "2024-03-18T10:13:54.150Z",
txHash: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
totalTxs: 1,
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false,
aliases: []
"identity_identifier": "8eTDkBhpQjHeqgbVeriwLeZr1tCa6yBGw76SckvD1cwc",
"alias": "canuseethat2.dash"
}
```
Response codes:
Expand All @@ -651,20 +664,25 @@ GET /identities?page=1&limit=10&order=asc&order_by=block_height
total: 10
},
resultSet: [
{
identifier: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
owner: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
revision: 1,
balance: 1000000,
timestamp: "2024-03-18T10:13:54.150Z",
txHash: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
totalTxs: 1,
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false,
aliases: ["test.dash"]
}, ...
{
identifier: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
owner: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec",
revision: 1,
balance: 1000000,
timestamp: "2024-03-18T10:13:54.150Z",
txHash: "DEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF",
totalTxs: 1,
totalTransfers: 0,
totalDocuments: 0,
totalDataContracts: 0,
isSystem: false,
aliases: [
{
alias: "alias.dash",
status: "locked"
}
]
}, ...
]
}
```
Expand Down Expand Up @@ -768,7 +786,8 @@ GET /identities/GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec/transactions?page=1
timestamp: "2024-03-18T10:13:54.150Z",
gasUsed: 1337000,
status: "SUCCESS",
error: null
error: null,
owner: "GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec"
}, ...
]
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"lint": "standard ."
},
"dependencies": {
"@dashevo/dapi-client": "1.5.1",
"@dashevo/dashd-rpc": "19.0.0",
"@fastify/cors": "^8.3.0",
"@scure/base": "^1.1.5",
Expand All @@ -24,7 +23,8 @@
"fastify-metrics": "^11.0.0",
"knex": "^2.5.1",
"node-fetch": "^2.6.11",
"pg": "^8.11.3"
"pg": "^8.11.3",
"@dashevo/dapi-client": "github:owl352/dapi-client"
},
"devDependencies": {
"standard": "^17.1.0",
Expand Down
35 changes: 35 additions & 0 deletions packages/api/src/DAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ class DAPI {
const { epochsInfo } = await this.dapi.platform.getEpochsInfo(start, count, { ascending })
return epochsInfo
}

/**
* Fetch the version upgrade votes status
* @typedef {getContestedState}
* @param {string} contractId - base64 contractId
* @param {string} documentTypeName
* @param {string} indexName
* @param {number} resultType
* @param {Array<Buffer>} indexValuesList
* @param {Buffer} [startAtIdentifierInfo]
* @param {bool} [allowIncludeLockedAndAbstainingVoteTally]
* @param {number} [count]
* @returns {Promise<contestedResourceContenders>}
*/
async getContestedState (contractId,
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
documentTypeName,
indexName,
resultType,
indexValuesList,
startAtIdentifierInfo,
allowIncludeLockedAndAbstainingVoteTally,
count
) {
const { contestedResourceContenders } = await this.dapi.platform.getContestedResourceVoteState(
Buffer.from(contractId, 'base64'),
documentTypeName,
indexName,
resultType,
indexValuesList,
startAtIdentifierInfo,
pshenmic marked this conversation as resolved.
Show resolved Hide resolved
allowIncludeLockedAndAbstainingVoteTally,
count
)
return contestedResourceContenders
}
}

module.exports = DAPI
1 change: 1 addition & 0 deletions packages/api/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let genesisTime
module.exports = {
EPOCH_CHANGE_TIME: Number(process.env.EPOCH_CHANGE_TIME),
TCP_CONNECT_TIMEOUT: Number(process.env.TCP_CONNECT_TIMEOUT),
DPNS_CONTRACT: 'GWRSAVFMjXx8HpQFaNJMqBV7MBgMK4br5UESsB4S31Ec',
get genesisTime () {
if (!genesisTime || isNaN(genesisTime)) {
return TenderdashRPC.getBlockByHeight(1).then((blockInfo) => {
Expand Down
21 changes: 6 additions & 15 deletions packages/api/src/controllers/IdentitiesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { IDENTITY_CREDIT_WITHDRAWAL } = require('../enums/StateTransitionEnum')

class IdentitiesController {
constructor (knex, dapi) {
this.identitiesDAO = new IdentitiesDAO(knex)
this.identitiesDAO = new IdentitiesDAO(knex, dapi)
this.dapi = dapi
}

Expand All @@ -16,36 +16,27 @@ class IdentitiesController {
return response.status(404).send({ message: 'not found' })
}

const balance = await this.dapi.getIdentityBalance(identifier)

response.send({ ...identity, balance })
response.send(identity)
}

getIdentityByDPNS = async (request, response) => {
getIdentityByDPNSName = async (request, response) => {
const { dpns } = request.query

const identity = await this.identitiesDAO.getIdentityByDPNS(dpns)
const identity = await this.identitiesDAO.getIdentityByDPNSName(dpns)

if (!identity) {
return response.status(404).send({ message: 'not found' })
}

const balance = await this.dapi.getIdentityBalance(identity.identifier)

response.send({ ...identity, balance })
response.send(identity)
}

getIdentities = async (request, response) => {
const { page = 1, limit = 10, order = 'asc', order_by: orderBy = 'block_height' } = request.query

const identities = await this.identitiesDAO.getIdentities(Number(page ?? 1), Number(limit ?? 10), order, orderBy)

const identitiesWithBalance = await Promise.all(identities.resultSet.map(async identity => {
const balance = await this.dapi.getIdentityBalance(identity.identifier)
return { ...identity, balance }
}))

response.send({ ...identities, resultSet: identitiesWithBalance })
response.send(identities)
}

getTransactionsByIdentity = async (request, response) => {
Expand Down
15 changes: 6 additions & 9 deletions packages/api/src/controllers/MainController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class MainController {
this.blocksDAO = new BlocksDAO(knex)
this.dataContractsDAO = new DataContractsDAO(knex)
this.documentsDAO = new DocumentsDAO(knex)
this.transactionsDAO = new TransactionsDAO(knex)
this.identitiesDAO = new IdentitiesDAO(knex)
this.transactionsDAO = new TransactionsDAO(knex, dapi)
this.identitiesDAO = new IdentitiesDAO(knex, dapi)
this.validatorsDAO = new ValidatorsDAO(knex)
this.dapi = dapi
}
Expand Down Expand Up @@ -115,9 +115,7 @@ class MainController {
const identity = await this.identitiesDAO.getIdentityByIdentifier(query)

if (identity) {
const balance = await this.dapi.getIdentityBalance(identity.identifier)

return response.send({ identity: { ...identity, balance } })
return response.send({ identity })
}

// search data contracts
Expand All @@ -135,13 +133,12 @@ class MainController {
}
}

// by dpns name
if (/^[^\s.]+(\.[^\s.]+)*$/.test(query)) {
const identity = await this.identitiesDAO.getIdentityByDPNS(query)
const identity = await this.identitiesDAO.getIdentityByDPNSName(query)

if (identity) {
const balance = await this.dapi.getIdentityBalance(identity.identifier)

return response.send({ identity: { ...identity, balance } })
return response.send({ identity })
}
}

Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/controllers/TransactionsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ const utils = require('../utils')
const { calculateInterval } = require('../utils')

class TransactionsController {
constructor (client, knex) {
constructor (client, knex, dapi) {
this.client = client
this.transactionsDAO = new TransactionsDAO(knex)
this.transactionsDAO = new TransactionsDAO(knex, dapi)
this.dapi = dapi
}

getTransactionByHash = async (request, reply) => {
Expand Down
Loading
Loading