|
| 1 | +using IXICore; |
| 2 | +using IXICore.RegNames; |
| 3 | + |
| 4 | +namespace SPIXI.MiniApps.ActionRequestModels |
| 5 | +{ |
| 6 | + public class RegNameAction<T> : MiniAppActionBase |
| 7 | + { |
| 8 | + public T data; |
| 9 | + public Address? feeRecipientAddress; |
| 10 | + public IxiNumber? feeAmount; |
| 11 | + public RegisteredNameRecord? nameRecord; |
| 12 | + public List<RegisteredNameDataRecord>? nameDataRecords; |
| 13 | + |
| 14 | + public RegNameAction(T data, string? feeRecipientAddress, string? feeAmount, byte[]? nameRecord, byte[][]? nameDataRecords) |
| 15 | + { |
| 16 | + this.data = data; |
| 17 | + if (feeRecipientAddress != null) |
| 18 | + { |
| 19 | + this.feeRecipientAddress = new Address(feeRecipientAddress); |
| 20 | + } |
| 21 | + |
| 22 | + if (feeAmount != null) |
| 23 | + { |
| 24 | + this.feeAmount = new IxiNumber(feeAmount); |
| 25 | + } |
| 26 | + |
| 27 | + if (nameRecord != null) |
| 28 | + { |
| 29 | + this.nameRecord = new RegisteredNameRecord(nameRecord); |
| 30 | + } |
| 31 | + |
| 32 | + if (nameDataRecords != null) |
| 33 | + { |
| 34 | + this.nameDataRecords = new(); |
| 35 | + foreach (var record in nameDataRecords) |
| 36 | + { |
| 37 | + this.nameDataRecords.Add(new RegisteredNameDataRecord(record, true)); |
| 38 | + } |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + public class RegNameActionBase |
| 44 | + { |
| 45 | + public RegNameInstruction instruction { get; protected set; } |
| 46 | + public string decodedName { get; protected set; } |
| 47 | + public byte[] name { get; protected set; } |
| 48 | + public Address nextPkHash { get; protected set; } |
| 49 | + public byte[] signaturePk { get; protected set; } |
| 50 | + public byte[] signature { get; protected set; } |
| 51 | + public RegNameActionBase(RegNameInstruction instruction, string name, string nextPkHash, byte[] signaturePk, byte[] signature) |
| 52 | + { |
| 53 | + this.instruction = instruction; |
| 54 | + this.decodedName = name; |
| 55 | + this.name = IxiNameUtils.encodeAndHashIxiName(name); |
| 56 | + if (nextPkHash != null) |
| 57 | + { |
| 58 | + this.nextPkHash = new Address(nextPkHash); |
| 59 | + } |
| 60 | + this.signaturePk = signaturePk; |
| 61 | + this.signature = signature; |
| 62 | + } |
| 63 | + |
| 64 | + protected RegNameActionBase() { } |
| 65 | + } |
| 66 | + |
| 67 | + public class RegNameRegisterAction : RegNameActionBase |
| 68 | + { |
| 69 | + public uint registrationTimeInBlocks { get; private set; } |
| 70 | + public Address recoveryHash { get; private set; } |
| 71 | + public uint capacity { get; private set; } |
| 72 | + |
| 73 | + public RegNameRegisterAction(string name, uint registrationTime, uint capacity, string nextPkHash, string recoveryHash) |
| 74 | + : base(RegNameInstruction.register, name, nextPkHash, null, null) |
| 75 | + { |
| 76 | + this.registrationTimeInBlocks = registrationTime; |
| 77 | + this.capacity = capacity; |
| 78 | + this.recoveryHash = new Address(recoveryHash); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public class RegNameExtendAction : RegNameActionBase |
| 83 | + { |
| 84 | + public uint extensionTimeInBlocks { get; private set; } |
| 85 | + public RegNameExtendAction(string name, uint extensionTimeInBlocks) |
| 86 | + : base(RegNameInstruction.extend, name, null, null, null) |
| 87 | + { |
| 88 | + this.extensionTimeInBlocks = extensionTimeInBlocks; |
| 89 | + } |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + public class RegNameChangeCapacityAction : RegNameActionBase |
| 94 | + { |
| 95 | + public uint newCapacity { get; private set; } |
| 96 | + public ulong sequence { get; private set; } |
| 97 | + |
| 98 | + public RegNameChangeCapacityAction(string name, uint newCapacity, ulong sequence, string nextPkHash, byte[] sigPk, byte[] signature) |
| 99 | + : base(RegNameInstruction.changeCapacity, name, nextPkHash, sigPk, signature) |
| 100 | + { |
| 101 | + this.newCapacity = newCapacity; |
| 102 | + this.sequence = sequence; |
| 103 | + } |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + public class RegNameRecoverAction : RegNameActionBase |
| 108 | + { |
| 109 | + public Address newRecoveryHash { get; private set; } |
| 110 | + public ulong sequence { get; private set; } |
| 111 | + public RegNameRecoverAction(string name, ulong sequence, string nextPkHash, string newRecoveryHash, byte[] recoveryPk, byte[] recoverySig) |
| 112 | + : base(RegNameInstruction.recover, name, nextPkHash, recoveryPk, recoverySig) |
| 113 | + { |
| 114 | + this.newRecoveryHash = new Address(newRecoveryHash); |
| 115 | + this.sequence = sequence; |
| 116 | + } |
| 117 | + |
| 118 | + } |
| 119 | + |
| 120 | + public class RegNameActionDataRecord |
| 121 | + { |
| 122 | + public string? name { get; private set; } |
| 123 | + public int ttl { get; private set; } |
| 124 | + public string data { get; private set; } |
| 125 | + public byte[]? checksum { get; private set; } |
| 126 | + |
| 127 | + public RegNameActionDataRecord(string? name, int ttl, string data, byte[]? checksum) |
| 128 | + { |
| 129 | + this.name = name; |
| 130 | + this.ttl = ttl; |
| 131 | + this.data = data; |
| 132 | + this.checksum = checksum; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + public class RegNameUpdateRecordsAction : RegNameActionBase |
| 137 | + { |
| 138 | + public RegNameActionDataRecord[] records { get; private set; } |
| 139 | + public ulong sequence { get; private set; } |
| 140 | + public RegNameUpdateRecordsAction(string name, RegNameActionDataRecord[] records, ulong sequence, string nextPkHash, byte[] pkSig, byte[] signature) |
| 141 | + : base(RegNameInstruction.updateRecord, name, nextPkHash, pkSig, signature) |
| 142 | + { |
| 143 | + this.records = records; |
| 144 | + this.sequence = sequence; |
| 145 | + } |
| 146 | + |
| 147 | + } |
| 148 | + |
| 149 | + public class RegNameToggleAllowSubnamesAction : RegNameActionBase |
| 150 | + { |
| 151 | + public bool allowSubnames { get; private set; } |
| 152 | + public IxiNumber fee { get; private set; } |
| 153 | + public Address feeRecipientAddress { get; private set; } |
| 154 | + public ulong sequence { get; private set; } |
| 155 | + |
| 156 | + public RegNameToggleAllowSubnamesAction(string name, bool allowSubnames, IxiNumber fee, string feeRecipientAddress, ulong sequence, string nextPkHash, byte[] pkSig, byte[] signature) |
| 157 | + : base(RegNameInstruction.toggleAllowSubnames, name, nextPkHash, pkSig, signature) |
| 158 | + { |
| 159 | + this.allowSubnames = allowSubnames; |
| 160 | + this.fee = fee; |
| 161 | + this.feeRecipientAddress = new Address(feeRecipientAddress); |
| 162 | + this.sequence = sequence; |
| 163 | + } |
| 164 | + |
| 165 | + } |
| 166 | +} |
0 commit comments