Skip to content

Commit

Permalink
feature: added new instructions to transfer domain ownerhsip and revo…
Browse files Browse the repository at this point in the history
…ke permissions

Signed-off-by: Timur Guskov <[email protected]>
  • Loading branch information
gv-timur committed Oct 18, 2023
1 parent d412f74 commit bfdea5d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ object Instructions {
),
)

/**
* Transfer domain ownership.
*/
fun transferDomainOwnership(sourceId: AccountId, value: IdBox.DomainId, destinationId: AccountId) =
InstructionBox.Transfer(
TransferBox(
sourceId = IdBox.AccountId(sourceId).evaluatesTo(),
`object` = Value.Id(value).evaluatesTo(),
destinationId = IdBox.AccountId(destinationId).evaluatesTo(),
),
)

/**
* Evaluate one instruction if a [condition] is met and another one otherwise.
*/
Expand Down Expand Up @@ -480,6 +492,30 @@ object Instructions {
}
}

/**
* Revoke an account the [Permissions.CanSetKeyValueInUserAccount] permission
*/
fun revokeSetKeyValueAccount(accountId: AccountId, target: AccountId): InstructionBox {
return revokeSome(IdBox.AccountId(target)) {
PermissionToken(
definitionId = Permissions.CanSetKeyValueInUserAccount.type,
payload = accountId.asJsonString().asStringWithJson(),
)
}
}

/**
* Revoke an account the [Permissions.CanSetKeyValueInDomain] permission
*/
fun revokeSetKeyValueDomain(domainId: DomainId, target: AccountId): InstructionBox {
return revokeSome(IdBox.AccountId(target)) {
PermissionToken(
definitionId = Permissions.CanSetKeyValueInDomain.type,
payload = domainId.asJsonString().asStringWithJson(),
)
}
}

/**
* Revoke an account a given role.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import jp.co.soramitsu.iroha2.generated.AssetValue
import jp.co.soramitsu.iroha2.generated.AssetValueType
import jp.co.soramitsu.iroha2.generated.DomainId
import jp.co.soramitsu.iroha2.generated.Executable
import jp.co.soramitsu.iroha2.generated.IdBox
import jp.co.soramitsu.iroha2.generated.InstructionBox
import jp.co.soramitsu.iroha2.generated.IpfsPath
import jp.co.soramitsu.iroha2.generated.Metadata
Expand Down Expand Up @@ -393,6 +394,10 @@ class TransactionBuilder(builder: TransactionBuilder.() -> Unit = {}) {
instructions.value.add(Instructions.transferAsset(sourceId, value, destinationId))
}

fun transferDomain(sourceId: AccountId, value: IdBox.DomainId, destinationId: AccountId) = this.apply {
instructions.value.add(Instructions.transferDomainOwnership(sourceId, value, destinationId))
}

fun `if`(condition: Boolean, then: InstructionBox, otherwise: InstructionBox) = this.apply {
instructions.value.add(Instructions.`if`(condition, then, otherwise))
}
Expand All @@ -412,6 +417,12 @@ class TransactionBuilder(builder: TransactionBuilder.() -> Unit = {}) {
fun revokeSetKeyValueAsset(assetId: AssetId, target: AccountId) =
this.apply { instructions.value.add(Instructions.revokeSetKeyValueAsset(assetId, target)) }

fun revokeSetKeyValueAccount(accountId: AccountId, target: AccountId) =
this.apply { instructions.value.add(Instructions.revokeSetKeyValueAccount(accountId, target)) }

fun revokeSetKeyValueDomain(domainId: DomainId, target: AccountId) =
this.apply { instructions.value.add(Instructions.revokeSetKeyValueDomain(domainId, target)) }

fun revokeRole(
roleId: RoleId,
accountId: AccountId,
Expand Down

0 comments on commit bfdea5d

Please sign in to comment.