コード例 #1
0
        public static async Task <IActionResult> RegisterDeployedContracts(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log,
            [Inject(typeof(AsymmetricAuthenticationHandler))] AsymmetricAuthenticationHandler auth,
            [Inject(typeof(IRepository <DeployedContract>))] IRepository <DeployedContract> repo)
        {
            var authResult = await auth.HandleAuthenticateAsync(req, log);

            if (!authResult.Succeeded)
            {
                return(new UnauthorizedResult());
            }

            var user = authResult.Principal.Identity.Name;

            string           requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            DeployedContract contract    = JsonConvert.DeserializeObject <DeployedContract>(requestBody);

            // Reset owner to address of authenticated user
            contract.OwnerAddress = user;

            var result = await repo.AddNew(contract);

            return(new OkObjectResult(result));
        }
コード例 #2
0
        public void TestGetScriptHash()
        {
            var contract = new DeployedContract(new ContractState()
            {
                Manifest = new Neo.SmartContract.Manifest.ContractManifest()
                {
                    Abi = new Neo.SmartContract.Manifest.ContractAbi()
                    {
                        Methods = new Neo.SmartContract.Manifest.ContractMethodDescriptor[]
                        {
                            new Neo.SmartContract.Manifest.ContractMethodDescriptor()
                            {
                                Name       = "verify",
                                Parameters = new Neo.SmartContract.Manifest.ContractParameterDefinition[0]
                            }
                        }
                    }
                },
                Nef = new NefFile {
                    Script = new byte[] { 1, 2, 3 }
                },
                Hash = new byte[] { 1, 2, 3 }.ToScriptHash()
            });

            Assert.AreEqual("0xb2e3fe334830b4741fa5d762f2ab36b90b86c49b", contract.ScriptHash.ToString());
        }
コード例 #3
0
ファイル: UT_DeployedContract.cs プロジェクト: xurxogp/neo
        public void TestGetAddress()
        {
            var contract = new DeployedContract(new ContractState()
            {
                Manifest = new Neo.SmartContract.Manifest.ContractManifest()
                {
                    Abi = new Neo.SmartContract.Manifest.ContractAbi()
                    {
                        Methods = new Neo.SmartContract.Manifest.ContractMethodDescriptor[]
                        {
                            new Neo.SmartContract.Manifest.ContractMethodDescriptor()
                            {
                                Name       = "verify",
                                Parameters = new Neo.SmartContract.Manifest.ContractParameterDefinition[0]
                            }
                        }
                    }
                },
                Script = new byte[] { 1, 2, 3 }
            });

            Assert.AreEqual("0xb2e3fe334830b4741fa5d762f2ab36b90b86c49b", contract.ScriptHash.ToString());
            Assert.AreEqual("Na7bMBy8KWZKSFBWTxeSKth1Je9AcWTpQM", contract.Address);
        }