Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | 1x 1x | import { config } from '../config' /** * @ignore */ function isNameValid(fullyQualifiedName: string = '') { const NAME_PART_RULE = /^[a-z0-9\-_+]+$/ const LENGTH_MAX_NAME = 37 if (!fullyQualifiedName || fullyQualifiedName.length > LENGTH_MAX_NAME) { return Promise.resolve(false) } const nameParts = fullyQualifiedName.split('.') if (nameParts.length !== 2) { return Promise.resolve(false) } return Promise.resolve( nameParts.reduce( (agg, namePart) => { if (!agg) { return false } else { return NAME_PART_RULE.test(namePart) } }, true ) ) } /** * @ignore */ function isNamespaceValid(namespaceID: string) { const NAMESPACE_RULE = /^[a-z0-9\-_]{1,19}$/ return Promise.resolve( namespaceID.match(NAMESPACE_RULE) !== null ) } /** * @ignore */ function isNameAvailable(fullyQualifiedName: string) { return config.network.getNameInfo(fullyQualifiedName) .then(() => false) .catch((e) => { if (e.message === 'Name not found') { return true } else { throw e } }) } /** * @ignore */ function isNamespaceAvailable(namespaceID: string) { return config.network.getNamespaceInfo(namespaceID) .then(() => false) .catch((e) => { if (e.message === 'Namespace not found') { return true } else { throw e } }) } /** * @ignore */ function ownsName(fullyQualifiedName: string, ownerAddress: string) { return config.network.getNameInfo(fullyQualifiedName) .then(nameInfo => nameInfo.address === ownerAddress) .catch((e) => { if (e.message === 'Name not found') { return false } else { throw e } }) } /** * @ignore */ function revealedNamespace(namespaceID: string, revealAddress: string) { return config.network.getNamespaceInfo(namespaceID) .then(namespaceInfo => namespaceInfo.recipient_address === revealAddress) .catch((e) => { if (e.message === 'Namespace not found') { return false } else { throw e } }) } /** * @ignore */ function namespaceIsReady(namespaceID: string) { return config.network.getNamespaceInfo(namespaceID) .then(namespaceInfo => namespaceInfo.ready) .catch((e) => { if (e.message === 'Namespace not found') { return false } else { throw e } }) } /** * @ignore */ function namespaceIsRevealed(namespaceID: string) { return config.network.getNamespaceInfo(namespaceID) .then(namespaceInfo => !namespaceInfo.ready) .catch((e) => { if (e.message === 'Namespace not found') { return false } else { throw e } }) } /** * @ignore */ function isInGracePeriod(fullyQualifiedName: string) { const network = config.network return Promise.all([network.getNameInfo(fullyQualifiedName), network.getBlockHeight(), network.getGracePeriod(fullyQualifiedName)]) .then(([nameInfo, blockHeight, gracePeriod]) => { const expiresAt = nameInfo.expire_block return (blockHeight >= expiresAt) && (blockHeight < (gracePeriod + expiresAt)) }) .catch((e) => { if (e.message === 'Name not found') { return false } else { throw e } }) } /** * @ignore */ function addressCanReceiveName(address: string) { return config.network.getNamesOwned(address) .then(names => (Promise.all(names.map(name => isNameValid(name))) .then(validNames => validNames.filter(nameValid => nameValid).length < 25))) } /** * @ignore */ function isAccountSpendable(address: string, tokenType: string, blockHeight: number) { return config.network.getAccountStatus(address, tokenType) .then(accountStatus => accountStatus.transfer_send_block_id >= blockHeight) } /** * @ignore */ export const safety = { addressCanReceiveName, isInGracePeriod, ownsName, isNameAvailable, isNameValid, isNamespaceValid, isNamespaceAvailable, revealedNamespace, namespaceIsReady, namespaceIsRevealed, isAccountSpendable } |