Skip to content

Instantly share code, notes, and snippets.

@Alexey-N-Chernyshov
Created August 16, 2018 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alexey-N-Chernyshov/696c8edea7106c4ac0990973a114aa67 to your computer and use it in GitHub Desktop.
Save Alexey-N-Chernyshov/696c8edea7106c4ac0990973a114aa67 to your computer and use it in GitHub Desktop.
Quorum example in Iroha
@Test
fun testQuorum() {
var keypair1 = ModelCrypto().generateKeypair()
var keypair2 = ModelCrypto().generateKeypair()
var txBuilder = ModelUtil.getModelTransactionBuilder()
var tx = txBuilder
.createdTime(ModelUtil.getCurrentTime())
.creatorAccountId("test@notary")
.createAccount("multisig", "notary", keypair1.publicKey())
.appendRole("multisig@notary", "tester")
.build()
irohaConsumer.sendAndCheck(tx)
txBuilder = ModelUtil.getModelTransactionBuilder()
tx = txBuilder
.createdTime(ModelUtil.getCurrentTime())
.creatorAccountId("multisig@notary")
.addSignatory("multisig@notary", keypair2.publicKey())
.setAccountQuorum("multisig@notary", 2)
.build()
var hash = tx.hash()
ModelUtil.prepareTransaction(tx, keypair1)
.flatMap { IrohaNetworkImpl(testConfig.iroha.hostname, testConfig.iroha.port).sendAndCheck(it, hash) }
val time = ModelUtil.getCurrentTime()
txBuilder = ModelUtil.getModelTransactionBuilder()
tx = txBuilder
.createdTime(time)
.creatorAccountId("multisig@notary")
.setAccountDetail("multisig@notary", "key", "value")
.build()
hash = tx.hash()
ModelUtil.prepareTransaction(tx, keypair1)
.flatMap { IrohaNetworkImpl(testConfig.iroha.hostname, testConfig.iroha.port).sendAndCheck(it, hash) }
println("wait")
Thread.sleep(5_000)
println("2nd send: $hash")
ModelUtil.prepareTransaction(tx, keypair2)
.flatMap { IrohaNetworkImpl(testConfig.iroha.hostname, testConfig.iroha.port).sendAndCheck(it, hash) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment