Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

add name service api #1155

Merged
merged 5 commits into from
Feb 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 19 additions & 19 deletions docs/en-us/reference/scapi/fw/dotnet/neo/NameService.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,29 @@ public class NameService

## Attributes

| Name | Description |
| -------- | -------------------- |
| Hash | Contract hash |
| 名称 | 说明 |
| -------- | ----------------- |
| Hash | Gets the contract hash |
| Symbol | Gets the symbol, NNS |
| Decimals | Gets the precision |
| Decimals | Gets decimals |

## Methods

| Name | Description |
| ---- | ---- |
| [TotalSupply()](NameService/TotalSupply.md) | Gets the total supply of NNS assets. |
| [BalanceOf(UInt160 owner)](NameService/BalanceOf.md) | Gets the number of domains the one owns |
| [OwnerOf(string name)](NameService/OwnerOf.md) | Gets owner of the domain |
| [Properties(string name)](NameService/Properties.md) | Gets properties of the domain |
| [Tokens()](NameService/Tokens.md) | Gets all domains contained in the contract |
| [TokensOf(UInt160 owner)](NameService/TokensOf.md) | Gets owner's domain |
| [Transfer(UInt160 from, UInt160 to, BigInteger amount)](NameService/Transfer.md) | Transfer assets |
| [IsAvailable(string name)](NameService/Transfer.md) | Is the domain available |
| [TotalSupply()](NameService/TotalSupply.md) | Gets the total supply of the domain token |
| [BalanceOf(UInt160 owner)](NameService/BalanceOf.md) | Gets the balance of the domain token with the specified owner address |
| [OwnerOf(string name)](NameService/OwnerOf.md) | Gets the owner of the domain token|
| [Properties(string name)](NameService/Properties.md) | Gets the properties of the domain token |
| [Tokens()](NameService/Tokens.md) | Gets all registered domains in the name service contract |
| [TokensOf(UInt160 owner)](NameService/TokensOf.md) | Gets all the domains owned by the specified address |
| [Transfer(UInt160, string)](NameService/Transfer.md) | Transfers the ownership of the domain |
| [IsAvailable(string name)](NameService/IsAvailable.md) | Checks if the domain is available |
| [Register(string name, UInt160 owner)](NameService/Register.md) | Registers a domain |
| [Renew(string name)](NameService/Renew.md) | Renews the domain |
| [SetAdmin(string name, UInt160 admin)](NameService/SetAdmin.md) | Sets domain administrator |
| [SetRecord(string name, RecordType type, string data)](NameService/SetRecord.md) | Sets DNS record |
| [GetRecord(string name, RecordType type)](NameService/GetRecord.md) | Gets DNS record |
| [DeleteRecord(string name, RecordType type)](NameService/DeleteRecord.md) | Deletes DNS record |
| [Resolve(string name, RecordType type)](NameService/Resolve.md) | Resolves DNS |
| [GetPrice()](NameService/GetPrice.md) | Gets the domain proce |
| [Renew(string name)](NameService/Renew.md) | Renews a domain |
| [SetAdmin(string name, UInt160 admin)](NameService/SetAdmin.md) | Sets the admin of the domain |
| [SetRecord(string name, RecordType type, string data)](NameService/SetRecord.md) | Sets the type data of the domain |
| [GetRecord(string name, RecordType type)](NameService/GetRecord.md) | Gets the type data of the domain |
| [DeleteRecord(string name, RecordType type)](NameService/DeleteRecord.md) | Deletes the type data of the domain |
| [Resolve(string name, RecordType type)](NameService/Resolve.md) | Resolves a domain |
| [GetPrice()](NameService/GetPrice.md) | Gets the price of registering or renewsing a domain |
48 changes: 48 additions & 0 deletions docs/en-us/reference/scapi/fw/dotnet/neo/NameService/BalanceOf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# BalanceOf method (UInt160)

Gets the registered domains of the specified address.

Namespace:[Neo.SmartContract.Framework.Services.Neo](../../neo.md)

Assembly:Neo.SmartContract.Framework


## Syntax

```c#
public static extern BigInteger BalanceOf(UInt160 owner);
```

Parameters:

- owner: the address hash to be queried.

## Example

```c#
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;

public class Demo : SmartContract
{
public static object BalanceOf(UInt160 Owner) => NameService.BalanceOf(Owner);
}
```

After deploying the contract in cli, then you can invoke the contract by typing `invoke 0x1b75e6ea52b9a825ec8d55038296970bf4641696 balanceOf [{"type":"Hash160","value":"0x75b75932a1451cc0c56a95eff7fcc01de45aa5a3"}]`,of which the response is shown as below:

```json
[{
"type":"Integer",
"value":"1"
}]
```

Response description:

- Integer type:the number of the domain of the specified address;

- Others:Failed.

[Back](../NameService.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# DeleteRecord method (string, RecordType)

Deletes the record data.

Namespace:[Neo.SmartContract.Framework.Services.Neo](../../neo.md)

Assembly:Neo.SmartContract.Framework

> [!Note]
>
> Needs to verify the signature of the admin or the owner of the domain name.
## Syntax

```c#
public static extern void DeleteRecord(string name, RecordType type);
```

parameters:

- name: domain name;
- type: record type.

## Example

```c#
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract;

public class Demo : SmartContract
{
public static void DeleteRecord(string name, byte type) => NameService.DeleteRecord(name, (RecordType)type);
}
```

After deploying the contract in cli,you can make a transaction by using [SDK](../../../../../../develop/tool/sdk/transaction.md) to query this method,

```c#
using Neo;
using Neo.Network.P2P.Payloads;
using Neo.Network.RPC;
using Neo.SmartContract;
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using System;
using System.Threading.Tasks;
using Utility = Neo.Network.RPC.Utility;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
TestNep17Transfer().GetAwaiter().GetResult();
Console.Read();
}

private static async Task TestNep17Transfer()
{
RpcClient client = new RpcClient("http://127.0.0.1:10332");
KeyPair ownerKey = Utility.GetKeyPair("KxrDM5H9TWiLtV48Ckxm15rp6XkxDHNryABGp1u67jRYpw3Y8z9G");
UInt160 owner = Contract.CreateSignatureContract(ownerKey.PublicKey).ScriptHash;

Signer[] cosigners = new[] { new Signer { Scopes = WitnessScope.CustomContracts, Account = owner, AllowedContracts = new UInt160[] { NativeContract.NameService.Hash } }};

// The hash of the contract we deployed above
UInt160 scriptHash = UInt160.Parse("0x7cc5d85855265ab974885d8852e7569208d3ca05");
byte[] script = scriptHash.MakeScript("deleteRecord", "test4.com", 1);

TransactionManager txManager = await new TransactionManagerFactory(client, 5195086)
.MakeTransactionAsync(script, cosigners).ConfigureAwait(false);
Transaction tx = await txManager.AddSignature(ownerKey).SignAsync().ConfigureAwait(false);

await client.SendRawTransactionAsync(tx).ConfigureAwait(false);
Console.WriteLine($"Transaction {tx.Hash.ToString()} is broadcasted!");

WalletAPI neoAPI = new WalletAPI(client);
await neoAPI.WaitTransactionAsync(tx)
.ContinueWith(async (p) => Console.WriteLine($"Transaction vm state is {(await p).VMState}"));
}
}
}
```

After running this program, you can get the response `Transaction 0xf66d7382949bf1700da3b86c59e1392b2d9003425d33998f68e76ccd7dfb1bfa is broadcasted!`, which means the success of the transaction.

[Back](../NameService.md)
43 changes: 43 additions & 0 deletions docs/en-us/reference/scapi/fw/dotnet/neo/NameService/GetPrice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# GetPrice method ()

Gets the price of registering or renewing a domain name.

Namespace:[Neo.SmartContract.Framework.Services.Neo](../../neo.md)

Assembly:Neo.SmartContract.Framework

## Syntax

```c#
public static extern long GetPrice();
```

## Example

```c#
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract;

public class Demo : SmartContract
{
public static long GetPrice() { return NameService.GetPrice(); }
}
```
After deploying the contract in cli, then you can invoke the contract by typing `invoke 0x0830764620067b85f374ef72b2e4f61b7020c620 getPrice`,of which the response is shown as below:

```json
[{
"type":"Integer",
"value":"1000000000"
}]
```

Response description:

- Integer type:10 Gas(the decimal is 8)。

- Others: failed.

[Back](../NameService.md)
48 changes: 48 additions & 0 deletions docs/en-us/reference/scapi/fw/dotnet/neo/NameService/GetRecord.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# GetRecord method (string, RecordType)

Gets the record data.

Namespace:[Neo.SmartContract.Framework.Services.Neo](../../neo.md)

Assembly:Neo.SmartContract.Framework

## Syntax

```c#
public static extern string GetRecord(string name, RecordType type);
```

parameters:

- name: domain name;
- RecordType: record type.

## Example

```c#
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract;

public class Demo : SmartContract
{
public static string GetRecord(string name, byte type) { return NameService.GetRecord(name, (RecordType)type); }
}
```
After deploying the contract in cli, then you can invoke the contract by typing `invoke 0x2d3b9ae14534f5b324dcd36f141272eac403e955 getRecord [{"type":"String","value":"test.com"},{"type":"Integer","value":"1"}]`,of which the response is shown as below:

```json
[{
"type":"ByteString",
"value":"MTI3LjAuMC4x" // 127.0.0.1
}]
```

Response description:

- ByteString type:the Base64-encoded string of the corresponding type data of the domain name;

- Others:failed.

[Back](../NameService.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# IsAvailable method (string)

Checks if the specified second domain name is available.

Namespace:[Neo.SmartContract.Framework.Services.Neo](../../neo.md)

Assembly:Neo.SmartContract.Framework

> [!Note]
>
> The corresponding first-level domain needs to be registered first, otherwise an exception will be thrown.

## Syntax

```c#
public static extern bool IsAvailable(string name);
```

parameters:

- name: the second domain name to be verified.

## Example

```c#
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;
using Neo.SmartContract;

public class Demo : SmartContract
{
public static bool IsAvailable(string name) { return NameService.IsAvailable(name); }
}
```

After deploying the contract in cli, then you can invoke the contract by typing `invoke 0x614a8f0015607d72cba71659ff83dea33cadb0c1 isAvailable [{"type":"String","value":"test.com"}]`,of which the response is shown as below:

```json
{
"type":"Boolean",
"value":"true"
}
```

Response description:

- Boolean type:available if true;

- Others:failed.

[Back](../NameService.md)
52 changes: 52 additions & 0 deletions docs/en-us/reference/scapi/fw/dotnet/neo/NameService/OwnerOf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# OwnerOf method (string)

Gets the address of the specified second domain.

Namespace:[Neo.SmartContract.Framework.Services.Neo](../../neo.md)

Assembly:Neo.SmartContract.Framework

> [!Note]
>
> Only the query for the second domain is supported。

## Syntax

```c#
public static extern UInt160 OwnerOf(string name);
```

Parameters:

- name: the second domain name to be queried.

## Example

```c#
using Neo;
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;

public class Demo : SmartContract
{
public static UInt160 OwnerOf(string name) => NameService.OwnerOf(name);
}

```

After deploying the contract in cli, then you can invoke the contract by typing `invoke 0xb35825371fd5ba98a58b4b043aa62e7b0082fd88 ownerOf [{"type":"String","value":"test.com"}]`,of which the response is shown as below:

```json
[{
"type":"ByteString",
"value":"o6Va5B3A/PfvlWrFwBxFoTJZt3U="
}]
```

Response description:

- ByteString type:Base64 encoded string of the account address to which the domain name belongs;

- Others: failed.

[Back](../NameService.md)
Loading