forked from neo-project/neo-devpack-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoot.Admin.cs
More file actions
85 lines (76 loc) · 2.88 KB
/
Copy pathLoot.Admin.cs
File metadata and controls
85 lines (76 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (C) 2015-2025 The Neo Project.
//
// Loot.Admin.cs file belongs to the neo project and is free
// software distributed under the MIT software license, see the
// accompanying file LICENSE in the main directory of the
// repository or http://www.opensource.org/licenses/mit-license.php
// for more details.
//
// Redistribution and use in source and binary forms with or without
// modifications are permitted.
using Neo.SmartContract.Framework;
using Neo.SmartContract.Framework.Attributes;
using Neo.SmartContract.Framework.Native;
using Neo.SmartContract.Framework.Services;
using System.Runtime.CompilerServices;
namespace NFT
{
/// <summary>
/// Security Requirements:
/// All public functions in this partial class
/// that has write permission must be owner only
///
/// [SetOwner] -- confirmed by jinghui
/// [_deploy] -- except this one, confirmed by jinghui
/// [Update] -- confirmed by jinghui
/// [Destroy] -- confirmed by jinghui
/// [Pause] -- confirmed by jinghui
/// [Resume] -- confirmed by jinghui
/// </summary>
public partial class Loot
{
private static readonly UInt160 Owner = "NaA5nQieb5YGg5nSFjhJMVEXQCQ5HdukwP";
/// <summary>
/// Security requirement:
/// The prefix should be unique in the contract: checked globally.
/// </summary>
private static readonly StorageMap OwnerMap = new(Storage.CurrentContext, (byte)StoragePrefix.Owner);
public static bool Verify() => Runtime.CheckWitness(GetOwner());
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void OwnerOnly() => ExecutionEngine.Assert(Verify(), "Authorization failed.");
/// <summary>
/// Security Requirements:
/// [0] Only the owner of the contract
/// are allowed to call this function: constrained internally
/// [1] the new address should be
/// a valid address: constrained internally
/// </summary>
/// <param name="newOwner"></param>
/// <returns></returns>
public static UInt160 SetOwner(UInt160 newOwner)
{
// <0> -- confirmed by jinghui
OwnerOnly();
// <1> -- confirmed by jinghui
ExecutionEngine.Assert(newOwner.IsValid, "Loot::UInt160 is invalid.");
OwnerMap.Put("owner", newOwner);
return GetOwner();
}
[Safe]
public static UInt160 GetOwner()
{
var owner = OwnerMap.Get("owner");
return owner != null ? (UInt160)owner : Owner;
}
public static void Update(ByteString nefFile, string manifest)
{
OwnerOnly();
ContractManagement.Update(nefFile, manifest, null);
}
public static void Destroy()
{
OwnerOnly();
ContractManagement.Destroy();
}
}
}