Singularity JS Library Documentation | Utopixia Docs

Singularity Function Documentation

Info

Observers are indexes maintained by the nodes that allow fast and efficient access to specific information. More details can be found in the Observers section.

GetFromObserver

Description: This function returns the value of a specific element from a given observer.

  • Arguments:
    • observerName (string): The name of the observer.
    • elementKey (string): The key of the element to retrieve.
  • Returns: The value of the element corresponding to elementKey. Returns undefined if errors occur or the element does not exist.

ExportObserver

Description: This function returns all entries of a given observer.

  • Arguments:
    • observerName (string): The name of the observer.
  • Returns: An object containing all the entries of the observer. Returns undefined in case of error.

AddTx

Description: This function adds a transaction to the blockchain.

Important

When a smart contract writes transactions, it uses the node's wallet.

For security reasons, only contracts authorized by the domains they operate on can write transactions.

  • Arguments:
    • recipient (string): The recipient of the transaction.
    • data (string): The data associated with the transaction.
    • amount (int64): The transaction amount.
    • callback (function, optional): A function called when the transaction is completed.
  • Returns:undefined. If a callback is provided, it is invoked with the transaction ID when the transaction is mined.

OnTransactionMined

Description: This function invokes a callback when the specified transaction is mined.

  • Arguments:
    • transactionID (string): The ID of the transaction.
    • callback (function): The function to call when the transaction is mined.
  • Returns:undefined.

IsValidTransaction

Description: This function checks the validity of a transaction.

  • Arguments:
    • transactionData (JSON object): The transaction data as a JSON object.
  • Returns:true if the transaction and its signature are valid, otherwise false.

FilterTx

Description: This function applies a filter to all transactions and returns those matching the filter criteria.

  • Arguments:
    • exprJSON (JSON object): The filter expression as a JSON object.
    • limit (int64, optional): The maximum number of transactions to return. If not specified, all matching transactions are returned.
  • Returns: A list of transactions matching the filter. Returns undefined in case of error.

Available Observers List

Observers extract data from added transactions to maintain a view of certain data. Here is a list of observers and the types of indexes they store:

  • IsRegistrarObserver
    • Name: pi:obs:registrar
    • Indexes:
      • Key: User Address
      • Value: "true" if the user is a registrar, "false" otherwise.

      • Info

        To prevent domain hijacking, only users in this group can register domain names on Utopixia.

  • GraphActionsObserver
    • Name: pi:obs:graph
    • Indexes:
      • Key: graphID
      • Value: Action count related to this graphID.
  • IsOwnerObserver
    • Name: pi:obs:owner
    • Indexes:
      • Key: graphID:address
      • Value: "true" if the address is the owner of the graph, "false" otherwise.
      • Key: graphID
      • Value: List of graph owners.
  • UserProfileObserver
    • Name: pi:obs:users:profile
    • Indexes:
      • Key: Blockchain address
      • Value: User profile graph ID.
  • StakeObserver
    • Name: pi:obs:stake
    • Indexes:
      • Key: Blockchain address
      • Value: Total amount staked by an address.
      • Key: Domain name
      • Value: Total amount staked for this domain.
  • DomainsObserver
    • Name: pi:obs:domains
    • Indexes:
      • Key: Domain name
      • Value: Blockchain address owning the domain.
      • Key: {domain}-ID
      • Value: Graph ID associated with the domain.
  • HasBeenRewardObserver
    • Name: pi:obs:rewards
    • Indexes:
      • Key: Receiver
      • Value: Reward count received by the address.
  • TokenTransfersObserver
    • Name: pi:obs:tokens
    • Indexes:
      • Key: Recipient
      • Value: Total amount of tokens received by the recipient.
      • Key: Sender
      • Value: Total amount of tokens sent by the sender.
      • Key: Recipient-stats
      • Value: Stats of tokens received by the recipient.
      • Key: Sender-stats
      • Value: Stats of tokens sent by the sender.