mirror of
https://github.com/corda/corda.git
synced 2025-01-29 15:43:55 +00:00
Contracts: add an issue crafting function to the cash contract.
This commit is contained in:
parent
aecc1de0cf
commit
28bd2053cc
@ -136,6 +136,16 @@ object Cash : Contract {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey.
|
||||
*/
|
||||
fun craftIssue(tx: PartialTransaction, amount: Amount, at: InstitutionReference, owner: PublicKey) {
|
||||
check(tx.inputStates().isEmpty())
|
||||
check(tx.outputStates().sumCashOrNull() == null)
|
||||
tx.addOutputState(Cash.State(at, amount, owner))
|
||||
tx.addArg(WireCommand(Cash.Commands.Issue(), listOf(at.institution.owningKey)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a transaction that consumes one or more of the given input states to move money to the given pubkey.
|
||||
* Note that the wallet list is not updated: it's up to you to do that.
|
||||
|
@ -108,6 +108,11 @@ class PartialTransaction(private val inputStates: MutableList<ContractStateRef>
|
||||
check(currentSigs.isEmpty())
|
||||
args.add(arg)
|
||||
}
|
||||
|
||||
// Accessors that yield immutable snapshots.
|
||||
fun inputStates(): List<ContractStateRef> = ArrayList(inputStates)
|
||||
fun outputStates(): List<ContractState> = ArrayList(outputStates)
|
||||
fun args(): List<WireCommand> = ArrayList(args)
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ import java.security.PublicKey
|
||||
import java.util.*
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class CashTests {
|
||||
val inState = Cash.State(
|
||||
@ -87,6 +88,16 @@ class CashTests {
|
||||
arg(MINI_CORP_KEY) { Cash.Commands.Issue() }
|
||||
this.accepts()
|
||||
}
|
||||
|
||||
val ptx = PartialTransaction()
|
||||
Cash.craftIssue(ptx, 100.DOLLARS, InstitutionReference(MINI_CORP, OpaqueBytes.of(12, 34)), owner = DUMMY_PUBKEY_1)
|
||||
assertTrue(ptx.inputStates().isEmpty())
|
||||
val s = ptx.outputStates()[0] as Cash.State
|
||||
assertEquals(100.DOLLARS, s.amount)
|
||||
assertEquals(MINI_CORP, s.deposit.institution)
|
||||
assertEquals(DUMMY_PUBKEY_1, s.owner)
|
||||
assertTrue(ptx.args()[0].command is Cash.Commands.Issue)
|
||||
assertEquals(MINI_CORP_KEY, ptx.args()[0].pubkeys[0])
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user