Rename algo to NIP-34asc

This commit is contained in:
arthurfranca 2023-06-27 11:15:05 -03:00
parent 5ddf4a3925
commit 537ad9f455
2 changed files with 14 additions and 20 deletions

13
34.md
View File

@ -46,8 +46,7 @@ Into this:
## How Clients Make Custom Requests for a Specific User
The algorithms are global, meaning the "score" represented by the new event field isn't considering
specific user preferences.
The algorithms are generic, meaning the "score" represented by the new event field does not differ for different users.
However, smart `clients` may keep track of pubkeys from whom the user is consuming content, also hashtags, for instance, and use such pubkeys/hashtags as a way to tailor the query to that specific user. For example:
@ -57,18 +56,18 @@ However, smart `clients` may keep track of pubkeys from whom the user is consumi
Each algorithm section describes **how** and **when** to compute the corresponding database field for each event.
For example, [NIP-34a](34a.md) extension teaches `relays` the math used to update the `nip34a` event field.
For example, [NIP-34asc](34asc.md) extension teaches `relays` the math used to update the `nip34asc` event field.
The NIP extension MUST have atleast one example in any programming language, preferably with inline comments.
All algorithms' field values MUST be **unique strings** for each event.
This is needed to support the most rudimentary databases that `relays` may be using such as file DBs.
The event id may be appended to the string to make it unique, similar to NIP-34a solution.
The event id may be appended to the string to make it unique, similar to NIP-34asc solution.
Bugfixes and small updates to embrace new event kinds may be submitted at any time by the algorithm author(s).
## Available Algorithms
| Extension | Name | Description | Modification Date |
| ------------- | ------------ | -------------------------------------------------- | ----------------- |
| [34a](34a.md) | Oldest First | Events with older `created_at` are retrieved first | 12 / jun / 2023 |
| Extension | Name | Description | Modification Date |
| ----------------- | ----------| -------------------------------------------------- | ----------------- |
| [34asc](34asc.md) | Ascending | Events with older `created_at` are retrieved first | 12 / jun / 2023 |

View File

@ -1,8 +1,8 @@
NIP-34a
=======
NIP-34asc
=========
Oldest First
------------
Ascending
---------
`draft` `optional` `author:arthurfranca`
@ -10,9 +10,9 @@ Events with older `created_at` are retrieved first.
## Implementation
`Relay` computes `nip34a` field once upon receiving the event.
`Relay` computes `nip34asc` field once upon receiving the event.
The lower the `created_at`, the higher `nip34a` will be.
The lower the `created_at`, the higher `nip34asc` will be.
### Javascript
@ -24,7 +24,7 @@ const maxDateNowSeconds = 8640000000000 // 8.64e15 ms / 1000
const maxTs = maxDateNowSeconds * 2
const maxSecondsLength = maxTs.toString().length
function getNip34a (createdAt, id = '') {
function getNip34asc (createdAt, id = '') {
// The id length must always be the same to not affect sorting
if (id.length !== 64) { throw new Error('Wrong id length') }
let seconds = Math.trunc(createdAt) // Make sure it is int instead of float
@ -42,10 +42,5 @@ function getNip34a (createdAt, id = '') {
return `${paddedTsSeconds}${id}`
}
event.nip34a = getNip34a(event.created_at, event.id)
event.nip34asc = getNip34asc(event.created_at, event.id)
```
## Notes
This implementation should be updated if we find out a popular programming
language doesn't support 17280000000000 int.