Access to data

2021-11-16 Access to data About 1 min

# Access to data

We use the interface provided by polkadot.js to demonstrate this, you can get more information here (opens new window).

# Get a reputation

The chain holds the last two updates of the user's reputation.

const result = await api.query.zdReputation.reputationScores(address)
1

Return:

[
    {
        nonce: 12,
        score: 1233
    },
    {
        nonce: 9,
        score: 1233
    }
]
1
2
3
4
5
6
7
8
9
10

nonce is the number of times the reputation system has been updated, you also need to get the system running status.

const result = await api.query.zdReputation.systemInfo()
1

Return:

{
  nonce: 12
  last: 156
  next: 140
  period: 100
  step: Free
}
1
2
3
4
5
6
7

If the nonce of a reputation value exceeds the system nonce during a system refresh, this means that the reputation has not been confirmed. A user's nonce that is too small may mean that the user has not been active recently, or other unforeseen circumstances. You can also trust this reputation value if you do not require a high security factor, for example in a movie rating application. If the application is in the financial category, the risk of trusting this reputation value should be carefully assessed.

# Trusted relationships

You can obtain the latest trust relationships of your users by.

const trustedList = await api.query.zdTrust.trustedList(address)
1

This will return an array of address, which is sufficient if you're using it to build social applications. But if you're using it to calculate reputation values and pick seeds, you'll also need to get trustTempList:

const trustTempList = await api.query.zdTrust.trustTempList(address)
1

Return:

{
    trust: [],
    untrust: []
}
1
2
3
4

This is used to cache the user's trust relationship before the system is refreshed, and if the user untrusts during the refresh period, it will be cached in trust. Therefore, you need to exclude untrust from trustedList and merge trust. The resulting data can then be used to calculate reputation and select seeds.

Last update: November 16, 2021 23:48
Contributors: DarkingLee