-
Notifications
You must be signed in to change notification settings - Fork 0
/
Iroha.scala
66 lines (54 loc) · 2.54 KB
/
Iroha.scala
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
import org.hyperledger.iroha.scaladsl
object Iroha {
case class DomainName(value: String) {
assert(0 < value.length && value.length <= 164, "domainName length must be between 1 to 164")
assert(IrohaValidator.isValidDomain(value), "domainName must satisfy the domain specifications (RFC1305).")
}
case class AssetName(value: String) {
assert(0 < value.length && value.length <= 9, "assetName length must be between 1 to 9")
assert(IrohaValidator.isAlphabetAndNumber(value), "assetName must be only alphabet or number. [a-zA-Z0-9]")
}
case class AccountName(value: String) {
assert(0 < value.length && value.length <= 32, "accountName length must be between 1 to 32")
assert(IrohaValidator.isAplhaNumberUnderscore(value), "accountName can only be alpha numeric plus a underscore. [a-z_0-9]")
assert(IrohaValidator.isValidDomain(value.replaceAll("_", "")), "accountName must satisfy the domain specifications (RFC1305).")
}
case class RoleName(value: String) {
assert(0 < value.length && value.length <= 7, "roleName length must be between 1 to 7")
assert(IrohaValidator.isAlphabetAndNumber(value) && IrohaValidator.isLowerCase(value), "roleName must be only lower alphabet. [a-z]")
}
case class AssetPrecision(value: Int) {
assert(0 <= value && value <= 255, "precision must be between 0 to 255")
}
case class TransferDescription(value: String) {
assert(64 >= value.length, "transferDescription size should be less than or equal to 64")
override def toString: String = value
}
case class Account(accountName: AccountName, domain: DomainName)
object Account {
def apply(name: String, domain: String): Account = new Account(AssetName(name), Domain(domain))
def apply(combined: String): Account = {
def apply(combined: String): Asset = {
val parts = combined.split("@")
assert(parts.length == 2)
Account(parts(0), parts(1))
}
}
}
case class Asset(assetName: AssetName, domain: DomainName)
object Asset {
def apply(name: String, domain: String): Asset = new Asset(AssetName(name), Domain(domain))
def apply(combined: String): Asset = {
val parts = combined.split("#")
assert(parts.length == 2)
Asset(parts(0), parts(1))
}
}
case class RoleId(roleName: IrohaRoleName) {
override def toString: String = s"${roleName.value}"
}
case class Amount(value: String, precision: IrohaAssetPrecision) {
private val isZeroOrPositive = BigDecimal(value) >= 0
assert(isZeroOrPositive, "amount must be greater equal than 0")
}
}