• 官网
  • 中文
  • English
  • Russian
  • More language
Show / Hide Table of Contents
  • Home
  • Getting Started
  • NEO Node
    • Introduction
    • Installation
    • Graphical User Interface
    • Test Network
    • CLI Reference
    • Private Chain
    • API Reference
      • dumpprivkey
      • getaccountstate
      • getassetstate
      • getbalance
      • getbestblockhash
      • getblock
      • getblock
      • getblockcount
      • getblockhash
      • getblocksysfee
      • getconnectioncount
      • getcontractstate
      • getnewaddress
      • getrawmempool
      • getrawtransaction
      • getstorage
      • gettxout
      • getpeers
      • getversion
      • invoke
      • invokefunction
      • invokescript
      • sendrawtransaction
      • sendtoaddress
      • sendmany
      • validateaddress
    • Network Protocol
    • Consensus
      • Consensus Whitepaper
      • Consensus Diagram
  • Smart Contract
    • Introduction
    • Getting Started (C#)
    • Getting Started (Java)
    • Getting Started (Python)
      • Using Prompt
      • Settings and Logging
      • Interacting with Smart Contracts
      • Tests
      • Python Compiler
    • Tutorial
      • Basics
      • Hello World
      • Lock Contract
      • Domain (Domain Name System)
      • Smart Contract Parameters and Return Values
      • Contract Authentication Tutorial
      • Deploying a Lock Contract
      • Contract Call
      • Deploying and Invoking
    • Test
    • Whitepaper
    • API Reference
      • NEO
      • System
    • Framework
      • .NET framework
        • NEO
          • Account
          • Asset
          • Block
          • Blockchain
          • Enrollment
          • Header
          • Storage
          • StorageContext
          • Transaction
          • TransactionAttribute
          • TransactionInput
          • TransactionOutput
        • System
          • ExecutionEngine
    • System Fees
  • Document for Exchange Developers
  • Contributors

Esempio di Smart Contract - Domain (Sistema dei Nomi di Dominio)

using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Services.Neo;

namespace Neo.SmartContract
{
    public class Domain : Framework.SmartContract
    {
        public static object Main(string operation, params object[] args)
        {
            switch (operation)
            {
                case "query":
                    return Query((string)args[0]);
                case "register":
                    return Register((string)args[0], (byte[])args[1]);
                case "transfer":
                    return Transfer((string)args[0], (byte[])args[1]);
                case "delete":
                    return Delete((string)args[0]);
                default:
                    return false;
            }
        }

        private static byte[] Query(string domain)
        {
            return Storage.Get(Storage.CurrentContext, domain);
        }

        private static bool Register(string domain, byte[] owner)
        {
            if (!Runtime.CheckWitness(owner)) return false;
            byte[] value = Storage.Get(Storage.CurrentContext, domain);
            if (value != null) return false;
            Storage.Put(Storage.CurrentContext, domain, owner);
            return true;
        }

        private static bool Transfer(string domain, byte[] to)
        {
            if (!Runtime.CheckWitness(to)) return false;
            byte[] from = Storage.Get(Storage.CurrentContext, domain);
            if (from == null) return false;
            if (!Runtime.CheckWitness(from)) return false;
            Storage.Put(Storage.CurrentContext, domain, to);
            return true;
        }

        private static bool Delete(string domain)
        {
            byte[] owner = Storage.Get(Storage.CurrentContext, domain);
            if (owner == null) return false;
            if (!Runtime.CheckWitness(owner)) return false;
            Storage.Delete(Storage.CurrentContext, domain);
            return true;
        }
    }
}

Il contratto implementa un sistema dei nomi di dominio, dove i nomi di dominio puntano ai dati sulla blockchain. Non é il vero sistema dei nomi di dominio di internet.

Il codice sopra implementa query, registrazione, trasferimento e cancellazione di nomi di dominio.

Per dettagli, fare riferimento a Storage.

  • Improve this Doc
Back to top Copyright © 2014-2018 NEO