elective-stereophonic
elective-stereophonic
Alias as an attribute or feature singapore
Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest Stable Nxt Client: Nxt 1.11.15 | Latest Experimental Nxt Client: Nxt 1.12.0e

Author Topic: Alias as an attribute or feature  (Read 2813 times)

ifinta

  • Jr. Member
  • **
  • Karma: +19/-0
  • Offline Offline
  • Posts: 89
    • View Profile
Alias as an attribute or feature
« on: April 18, 2015, 09:05:13 pm »

I will use the Alias system to store attributes or features of an account or its owner.

The key of such an alias should be:

<n><attr>

<n> is a NXT account's ID (numerical, not RS). This account owns this alias. If not, does not matter.
<attr> is a name of an attribute

for example:

7097035329320774794bestMusic

or

16850671977888229764bestMusic

This alias should contain an URL to the favourite music of the account's owner.

Can you please comment...

To see (or maybe try) it in work, please read:
https://nxtforum.org/assets-board/%28ann%29-bestmusic-asset-let%27s-get-to-know-each-others-favourites/
« Last Edit: June 01, 2015, 08:05:05 pm by ifinta »
Logged

Jean-Luc

  • Core Dev
  • Hero Member
  • *****
  • Karma: +816/-81
  • Offline Offline
  • Posts: 1610
    • View Profile
Re: Alias as an attribute or feature
« Reply #1 on: April 19, 2015, 08:16:55 am »

Fits like a square peg in a round hole.

I will see if I can add account properties in 1.5.4 if I have time.
Logged
GPG key fingerprint: 263A 9EB0 29CF C77A 3D06  FD13 811D 6940 E1E4 240C
NXT-X4LF-9A4G-WN9Z-2R322

ifinta

  • Jr. Member
  • **
  • Karma: +19/-0
  • Offline Offline
  • Posts: 89
    • View Profile
Re: Alias as an attribute or feature
« Reply #2 on: April 19, 2015, 10:17:00 am »

Fits like a square peg in a round hole.
Yes, I know.

I will see if I can add account properties in 1.5.4 if I have time.
Exists API description for the properties already? Where can I get it?
Logged

Jean-Luc

  • Core Dev
  • Hero Member
  • *****
  • Karma: +816/-81
  • Offline Offline
  • Posts: 1610
    • View Profile
Re: Alias as an attribute or feature
« Reply #3 on: April 19, 2015, 10:23:53 am »

Still in my head only. But I imagine a single setAccountProperty API which takes a name and a value, similar to aliases but account specific, name unique within the account only, update the value if already existing or delete the name/value pair if value empty. And getAccountProperties which returns all of them for a given account (should limit to 100 max properties allowed).
Logged
GPG key fingerprint: 263A 9EB0 29CF C77A 3D06  FD13 811D 6940 E1E4 240C
NXT-X4LF-9A4G-WN9Z-2R322

verymuchso

  • Hero Member
  • *****
  • Karma: +118/-2
  • Offline Offline
  • Posts: 549
    • View Profile
    • HEAT Ledger
Re: Alias as an attribute or feature
« Reply #4 on: April 19, 2015, 11:49:35 am »

Still in my head only. But I imagine a single setAccountProperty API which takes a name and a value, similar to aliases but account specific, name unique within the account only, update the value if already existing or delete the name/value pair if value empty. And getAccountProperties which returns all of them for a given account (should limit to 100 max properties allowed).

For FIMK I have implemented exactly this feature some 6 months ago.
They needed it for their basic income to Fins and a couple of other purposes which are not widely used yet.

To make it more useful I have added a simple query language that makes the feature seems a bit like a key/value store not unlike Redis for example.
Keys are supposed to be in the form "main.sub.detail" and the query API allows you to query for "main.sub.*" which returns all values in the "main.sub" key range.

The NXT alias implementation was a big inspiration on how to tackle this problem so I dont mind it at all if parts of are used directly or perhaps as inspiration.
It lacks some optimizations like for instance DB level %LIKE queries instead of the java iterator/filter but as i said it's not widely used so there are no problems as such.

So in the spirit of open source and giving back have a look if anyone is interested.

https://github.com/fimkrypto/fimk/blob/master/src/java/nxt/NamespacedAlias.java
https://github.com/fimkrypto/fimk/blob/master/src/java/nxt/http/GetNamespacedAliases.java
https://github.com/fimkrypto/fimk/blob/master/src/java/nxt/http/GetNamespacedAlias.java
https://github.com/fimkrypto/fimk/blob/master/src/java/nxt/http/SetNamespacedAlias.java

Cheers
Dirk
Logged
HEAT: DEX | SDK | HOME

verymuchso

  • Hero Member
  • *****
  • Karma: +118/-2
  • Offline Offline
  • Posts: 549
    • View Profile
    • HEAT Ledger
Re: Alias as an attribute or feature
« Reply #5 on: April 19, 2015, 11:55:31 am »

I realize now that mofowallet lacks UI for namespaced aliases, probably overlooked that since it's only used in-house and from an automated script.
If i get a chance i'll add edit functionality to mofowallet.

The main account using that feature can be seen here.. https://www.mofowallet.com/launch.html#/accounts/FIM-6AMG-V87K-SRJF-4BLHP/activity/latest

So if NamespacedAlias would be a contender for implementing this in NXT, you'll get free mofo compatibility  8)
Logged
HEAT: DEX | SDK | HOME

ifinta

  • Jr. Member
  • **
  • Karma: +19/-0
  • Offline Offline
  • Posts: 89
    • View Profile
Re: Alias as an attribute or feature
« Reply #6 on: April 19, 2015, 01:44:18 pm »

Still in my head only. But I imagine a single setAccountProperty API which takes a name and a value, similar to aliases but account specific, name unique within the account only, update the value if already existing or delete the name/value pair if value empty. And getAccountProperties which returns all of them for a given account (should limit to 100 max properties allowed).
Thank you.
I think it is clear, simple and round :)

But. I think the owner of the same named properties form a community. That is a list in the GUI, they can vote e.g.

I planned this to implement through an asset - it is a square peg too...
Logged

ifinta

  • Jr. Member
  • **
  • Karma: +19/-0
  • Offline Offline
  • Posts: 89
    • View Profile
Re: Alias as an attribute or feature
« Reply #7 on: June 01, 2015, 08:07:39 pm »

Logged

ifinta

  • Jr. Member
  • **
  • Karma: +19/-0
  • Offline Offline
  • Posts: 89
    • View Profile
Re: Alias as an attribute or feature
« Reply #8 on: July 03, 2015, 06:22:17 pm »

About BestMusic implementation - see http://myfavourite.tips too:

Code: [Select]
<h1>Top 100 music of the NXT blockchain:</h1>
<table border="1" style="width:100%">
<tr>
<td>Nr.</td><td>URI (if count > 4 then clickable)</td><td>sum of asset value</td><td>count of accounts</td><td>[RS address of the account, if count = 1]</td>
</tr>
<?php
$getAccounts 
file_get_contents('http://localhost:7876/nxt?requestType=getAssetAccounts&asset=7886298454495058445');
$obj_accounts json_decode($getAccounts);
$num count($obj_accounts->{'accountAssets'});

class 
UriData 
{
    public 
$uri;
    public 
$shares;
    public 
$count;
    public 
$first_account;
}

// reverse sort by shares
function rsortByShares($a$b
{
  if(
$a->shares == $b->shares
  {
    return 
0;
  } 
  else 
  {
    return (
$a->shares $b->shares) ? : -1;
  }
}

$arr = array();

// create a list of uri's
for($i 0$i $num$i++)
{
// attributes of an uri
   
$account $obj_accounts->{'accountAssets'}[$i]->{'account'};
   
$quantityQNT $obj_accounts->{'accountAssets'}[$i]->{'quantityQNT'};
   
$getAlias file_get_contents('http://localhost:7876/nxt?requestType=getAlias&aliasName='.$account.'bestMusic');
   
$obj_alias json_decode($getAlias);
   
$uri $obj_alias->{'aliasURI'};
   
$uri_account $obj_alias->{'account'};
   
$uri_accountRS $obj_alias->{'accountRS'};
   
$uri filter_var($uriFILTER_SANITIZE_URL);

   if(
filter_var($uriFILTER_VALIDATE_URL) && $account == $uri_account)
   {
       if(
array_key_exists($uri,$arr))
       {
           
$arr[$uri]->shares += $quantityQNT;
           
$arr[$uri]->count += 1;
       }
       else
       {
       $obj = new UriData();

           
$obj->uri $uri;
           
$obj->shares $quantityQNT;
           
$obj->count 1;
           
$obj->first_account $uri_accountRS;
           
           
$arr[$uri] = $obj;
       }
   }
}

$count 0;

// sort it...
usort($arr'rsortByShares');

// create a table
foreach($arr as $uri => $value)
{
   echo 
'<tr>';
   
$count++;
   
   if(
$value->count 5)
   {
      echo 
'<td>';
      echo 
$count.'.';
      echo 
'</td>';
      echo 
'<td>';
      echo 
htmlspecialchars($value->uri);
      echo 
'</td>';
      echo 
'<td>';
      echo (
$value->shares/100);
      echo 
'</td>';
      echo 
'<td>';
      echo (
$value->count);
      echo 
'</td>';
      echo 
'<td>';
      if(
$value->count == 1)
      {
          echo 
' '.($value->first_account);
      }
      else
      {
          echo 
' ';
      }
      echo 
'</td>';
   }
   else
   {
      echo 
'<td>';
      echo 
$count.'.'
      echo 
'</td>';
      echo 
'<td>';
      echo 
'<a href="';
      echo 
htmlspecialchars($value->uri);
      echo 
'" target="_blank">';
      echo 
htmlspecialchars($value->uri);
      echo 
'</a>';
      echo 
'</td>';
      echo 
'<td>';
      echo (
$value->shares/100);
      echo 
'</td>';
      echo 
'<td>';
      echo (
$value->count);
      echo 
'</td>';
      echo 
'<td> </td>';
   }
   echo 
'</tr>';
   
   if(
$count >= 100)
       break;
}
?>

</table>

Logged

Jean-Luc

  • Core Dev
  • Hero Member
  • *****
  • Karma: +816/-81
  • Offline Offline
  • Posts: 1610
    • View Profile
Re: Alias as an attribute or feature
« Reply #9 on: October 16, 2015, 11:52:15 pm »

I will see if I can add account properties in 1.5.4 if I have time.
Done for 1.7.
Logged
GPG key fingerprint: 263A 9EB0 29CF C77A 3D06  FD13 811D 6940 E1E4 240C
NXT-X4LF-9A4G-WN9Z-2R322

ifinta

  • Jr. Member
  • **
  • Karma: +19/-0
  • Offline Offline
  • Posts: 89
    • View Profile
Re: Alias as an attribute or feature
« Reply #10 on: October 17, 2015, 06:49:52 am »

I will see if I can add account properties in 1.5.4 if I have time.
Done for 1.7.

Thank you!
Logged
 

elective-stereophonic
elective-stereophonic
assembly
assembly