mirror of
https://github.com/corda/corda.git
synced 2025-06-21 16:49:45 +00:00
Rename ContractStateRef -> StateRef. Rename craft* methods to generate*
This commit is contained in:
@ -226,7 +226,7 @@ public class JavaCommercialPaper implements Contract {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void generateRedeem(TransactionBuilder tx, StateAndRef<State> paper, List<StateAndRef<Cash.State>> wallet) throws InsufficientBalanceException {
|
public void generateRedeem(TransactionBuilder tx, StateAndRef<State> paper, List<StateAndRef<Cash.State>> wallet) throws InsufficientBalanceException {
|
||||||
new Cash().craftSpend(tx, paper.getState().getFaceValue(), paper.getState().getOwner(), wallet, null);
|
new Cash().generateSpend(tx, paper.getState().getFaceValue(), paper.getState().getOwner(), wallet, null);
|
||||||
tx.addInputState(paper.getRef());
|
tx.addInputState(paper.getRef());
|
||||||
tx.addCommand(new Command( new Commands.Redeem(), paper.getState().getOwner()));
|
tx.addCommand(new Command( new Commands.Redeem(), paper.getState().getOwner()));
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ class Cash : Contract {
|
|||||||
/**
|
/**
|
||||||
* Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey.
|
* Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey.
|
||||||
*/
|
*/
|
||||||
fun craftIssue(tx: TransactionBuilder, amount: Amount, at: PartyReference, owner: PublicKey) {
|
fun generateIssue(tx: TransactionBuilder, amount: Amount, at: PartyReference, owner: PublicKey) {
|
||||||
check(tx.inputStates().isEmpty())
|
check(tx.inputStates().isEmpty())
|
||||||
check(tx.outputStates().sumCashOrNull() == null)
|
check(tx.outputStates().sumCashOrNull() == null)
|
||||||
tx.addOutputState(Cash.State(at, amount, owner))
|
tx.addOutputState(Cash.State(at, amount, owner))
|
||||||
@ -168,8 +168,8 @@ class Cash : Contract {
|
|||||||
* about which type of cash claims they are willing to accept.
|
* about which type of cash claims they are willing to accept.
|
||||||
*/
|
*/
|
||||||
@Throws(InsufficientBalanceException::class)
|
@Throws(InsufficientBalanceException::class)
|
||||||
fun craftSpend(tx: TransactionBuilder, amount: Amount, to: PublicKey,
|
fun generateSpend(tx: TransactionBuilder, amount: Amount, to: PublicKey,
|
||||||
cashStates: List<StateAndRef<Cash.State>>, onlyFromParties: Set<Party>? = null): List<PublicKey> {
|
cashStates: List<StateAndRef<Cash.State>>, onlyFromParties: Set<Party>? = null): List<PublicKey> {
|
||||||
// Discussion
|
// Discussion
|
||||||
//
|
//
|
||||||
// This code is analogous to the Wallet.send() set of methods in bitcoinj, and has the same general outline.
|
// This code is analogous to the Wallet.send() set of methods in bitcoinj, and has the same general outline.
|
||||||
|
@ -125,7 +125,7 @@ class CommercialPaper : Contract {
|
|||||||
* an existing transaction because you aren't able to issue multiple pieces of CP in a single transaction
|
* an existing transaction because you aren't able to issue multiple pieces of CP in a single transaction
|
||||||
* at the moment: this restriction is not fundamental and may be lifted later.
|
* at the moment: this restriction is not fundamental and may be lifted later.
|
||||||
*/
|
*/
|
||||||
fun craftIssue(issuance: PartyReference, faceValue: Amount, maturityDate: Instant): TransactionBuilder {
|
fun generateIssue(issuance: PartyReference, faceValue: Amount, maturityDate: Instant): TransactionBuilder {
|
||||||
val state = State(issuance, issuance.party.owningKey, faceValue, maturityDate)
|
val state = State(issuance, issuance.party.owningKey, faceValue, maturityDate)
|
||||||
return TransactionBuilder().withItems(state, Command(Commands.Issue(), issuance.party.owningKey))
|
return TransactionBuilder().withItems(state, Command(Commands.Issue(), issuance.party.owningKey))
|
||||||
}
|
}
|
||||||
@ -133,7 +133,7 @@ class CommercialPaper : Contract {
|
|||||||
/**
|
/**
|
||||||
* Updates the given partial transaction with an input/output/command to reassign ownership of the paper.
|
* Updates the given partial transaction with an input/output/command to reassign ownership of the paper.
|
||||||
*/
|
*/
|
||||||
fun craftMove(tx: TransactionBuilder, paper: StateAndRef<State>, newOwner: PublicKey) {
|
fun generateMove(tx: TransactionBuilder, paper: StateAndRef<State>, newOwner: PublicKey) {
|
||||||
tx.addInputState(paper.ref)
|
tx.addInputState(paper.ref)
|
||||||
tx.addOutputState(paper.state.copy(owner = newOwner))
|
tx.addOutputState(paper.state.copy(owner = newOwner))
|
||||||
tx.addCommand(Commands.Move(), paper.state.owner)
|
tx.addCommand(Commands.Move(), paper.state.owner)
|
||||||
@ -147,9 +147,9 @@ class CommercialPaper : Contract {
|
|||||||
* @throws InsufficientBalanceException if the wallet doesn't contain enough money to pay the redeemer
|
* @throws InsufficientBalanceException if the wallet doesn't contain enough money to pay the redeemer
|
||||||
*/
|
*/
|
||||||
@Throws(InsufficientBalanceException::class)
|
@Throws(InsufficientBalanceException::class)
|
||||||
fun craftRedeem(tx: TransactionBuilder, paper: StateAndRef<State>, wallet: List<StateAndRef<Cash.State>>) {
|
fun generateRedeem(tx: TransactionBuilder, paper: StateAndRef<State>, wallet: List<StateAndRef<Cash.State>>) {
|
||||||
// Add the cash movement using the states in our wallet.
|
// Add the cash movement using the states in our wallet.
|
||||||
Cash().craftSpend(tx, paper.state.faceValue, paper.state.owner, wallet)
|
Cash().generateSpend(tx, paper.state.faceValue, paper.state.owner, wallet)
|
||||||
tx.addInputState(paper.ref)
|
tx.addInputState(paper.ref)
|
||||||
tx.addCommand(CommercialPaper.Commands.Redeem(), paper.state.owner)
|
tx.addCommand(CommercialPaper.Commands.Redeem(), paper.state.owner)
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ class CrowdFund : Contract {
|
|||||||
* Returns a transaction that registers a crowd-funding campaing, owned by the issuing institution's key. Does not update
|
* Returns a transaction that registers a crowd-funding campaing, owned by the issuing institution's key. Does not update
|
||||||
* an existing transaction because it's not possible to register multiple campaigns in a single transaction
|
* an existing transaction because it's not possible to register multiple campaigns in a single transaction
|
||||||
*/
|
*/
|
||||||
fun craftRegister(owner: PartyReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): TransactionBuilder {
|
fun generateRegister(owner: PartyReference, fundingTarget: Amount, fundingName: String, closingTime: Instant): TransactionBuilder {
|
||||||
val campaign = Campaign(owner = owner.party.owningKey, name = fundingName, target = fundingTarget, closingTime = closingTime)
|
val campaign = Campaign(owner = owner.party.owningKey, name = fundingName, target = fundingTarget, closingTime = closingTime)
|
||||||
val state = State(campaign)
|
val state = State(campaign)
|
||||||
return TransactionBuilder().withItems(state, Command(Commands.Register(), owner.party.owningKey))
|
return TransactionBuilder().withItems(state, Command(Commands.Register(), owner.party.owningKey))
|
||||||
@ -151,7 +151,7 @@ class CrowdFund : Contract {
|
|||||||
/**
|
/**
|
||||||
* Updates the given partial transaction with an input/output/command to fund the opportunity.
|
* Updates the given partial transaction with an input/output/command to fund the opportunity.
|
||||||
*/
|
*/
|
||||||
fun craftPledge(tx: TransactionBuilder, campaign: StateAndRef<State>, subscriber: PublicKey) {
|
fun generatePledge(tx: TransactionBuilder, campaign: StateAndRef<State>, subscriber: PublicKey) {
|
||||||
tx.addInputState(campaign.ref)
|
tx.addInputState(campaign.ref)
|
||||||
tx.addOutputState(campaign.state.copy(
|
tx.addOutputState(campaign.state.copy(
|
||||||
pledges = campaign.state.pledges + CrowdFund.Pledge(subscriber, 1000.DOLLARS)
|
pledges = campaign.state.pledges + CrowdFund.Pledge(subscriber, 1000.DOLLARS)
|
||||||
@ -159,14 +159,14 @@ class CrowdFund : Contract {
|
|||||||
tx.addCommand(Commands.Pledge(), subscriber)
|
tx.addCommand(Commands.Pledge(), subscriber)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun craftClose(tx: TransactionBuilder, campaign: StateAndRef<State>, wallet: List<StateAndRef<Cash.State>>) {
|
fun generateClose(tx: TransactionBuilder, campaign: StateAndRef<State>, wallet: List<StateAndRef<Cash.State>>) {
|
||||||
tx.addInputState(campaign.ref)
|
tx.addInputState(campaign.ref)
|
||||||
tx.addOutputState(campaign.state.copy(closed = true))
|
tx.addOutputState(campaign.state.copy(closed = true))
|
||||||
tx.addCommand(Commands.Close(), campaign.state.campaign.owner)
|
tx.addCommand(Commands.Close(), campaign.state.campaign.owner)
|
||||||
// If campaign target has not been met, compose cash returns
|
// If campaign target has not been met, compose cash returns
|
||||||
if (campaign.state.pledgedAmount < campaign.state.campaign.target) {
|
if (campaign.state.pledgedAmount < campaign.state.campaign.target) {
|
||||||
for (pledge in campaign.state.pledges) {
|
for (pledge in campaign.state.pledges) {
|
||||||
Cash().craftSpend(tx, pledge.amount, pledge.owner, wallet)
|
Cash().generateSpend(tx, pledge.amount, pledge.owner, wallet)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ object TwoPartyTradeProtocol {
|
|||||||
// Add input and output states for the movement of cash, by using the Cash contract to generate the states.
|
// Add input and output states for the movement of cash, by using the Cash contract to generate the states.
|
||||||
val wallet = serviceHub.walletService.currentWallet
|
val wallet = serviceHub.walletService.currentWallet
|
||||||
val cashStates = wallet.statesOfType<Cash.State>()
|
val cashStates = wallet.statesOfType<Cash.State>()
|
||||||
val cashSigningPubKeys = Cash().craftSpend(ptx, tradeRequest.price, tradeRequest.sellerOwnerKey, cashStates)
|
val cashSigningPubKeys = Cash().generateSpend(ptx, tradeRequest.price, tradeRequest.sellerOwnerKey, cashStates)
|
||||||
// Add inputs/outputs/a command for the movement of the asset.
|
// Add inputs/outputs/a command for the movement of the asset.
|
||||||
ptx.addInputState(tradeRequest.assetForSale.ref)
|
ptx.addInputState(tradeRequest.assetForSale.ref)
|
||||||
// Just pick some new public key for now. This won't be linked with our identity in any way, which is what
|
// Just pick some new public key for now. This won't be linked with our identity in any way, which is what
|
||||||
|
@ -39,17 +39,16 @@ interface OwnableState : ContractState {
|
|||||||
/** Returns the SHA-256 hash of the serialised contents of this state (not cached!) */
|
/** Returns the SHA-256 hash of the serialised contents of this state (not cached!) */
|
||||||
fun ContractState.hash(): SecureHash = SecureHash.sha256(serialize().bits)
|
fun ContractState.hash(): SecureHash = SecureHash.sha256(serialize().bits)
|
||||||
|
|
||||||
// TODO: Give this a shorter name.
|
|
||||||
/**
|
/**
|
||||||
* A stateref is a pointer to a state, this is an equivalent of an "outpoint" in Bitcoin. It records which transaction
|
* A stateref is a pointer (reference) to a state, this is an equivalent of an "outpoint" in Bitcoin. It records which
|
||||||
* defined the state and where in that transaction it was.
|
* transaction defined the state and where in that transaction it was.
|
||||||
*/
|
*/
|
||||||
data class ContractStateRef(val txhash: SecureHash, val index: Int) {
|
data class StateRef(val txhash: SecureHash, val index: Int) {
|
||||||
override fun toString() = "$txhash($index)"
|
override fun toString() = "$txhash($index)"
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A StateAndRef is simply a (state, ref) pair. For instance, a wallet (which holds available assets) contains these. */
|
/** A StateAndRef is simply a (state, ref) pair. For instance, a wallet (which holds available assets) contains these. */
|
||||||
data class StateAndRef<out T : ContractState>(val state: T, val ref: ContractStateRef)
|
data class StateAndRef<out T : ContractState>(val state: T, val ref: StateRef)
|
||||||
|
|
||||||
/** A [Party] is well known (name, pubkey) pair. In a real system this would probably be an X.509 certificate. */
|
/** A [Party] is well known (name, pubkey) pair. In a real system this would probably be an X.509 certificate. */
|
||||||
data class Party(val name: String, val owningKey: PublicKey) {
|
data class Party(val name: String, val owningKey: PublicKey) {
|
||||||
|
@ -11,7 +11,7 @@ package core
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class TransactionResolutionException(val hash: SecureHash) : Exception()
|
class TransactionResolutionException(val hash: SecureHash) : Exception()
|
||||||
class TransactionConflictException(val conflictRef: ContractStateRef, val tx1: LedgerTransaction, val tx2: LedgerTransaction) : Exception()
|
class TransactionConflictException(val conflictRef: StateRef, val tx1: LedgerTransaction, val tx2: LedgerTransaction) : Exception()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A TransactionGroup defines a directed acyclic graph of transactions that can be resolved with each other and then
|
* A TransactionGroup defines a directed acyclic graph of transactions that can be resolved with each other and then
|
||||||
@ -33,7 +33,7 @@ class TransactionGroup(val transactions: Set<LedgerTransaction>, val nonVerified
|
|||||||
check(transactions.intersect(nonVerifiedRoots).isEmpty())
|
check(transactions.intersect(nonVerifiedRoots).isEmpty())
|
||||||
|
|
||||||
val hashToTXMap: Map<SecureHash, List<LedgerTransaction>> = (transactions + nonVerifiedRoots).groupBy { it.hash }
|
val hashToTXMap: Map<SecureHash, List<LedgerTransaction>> = (transactions + nonVerifiedRoots).groupBy { it.hash }
|
||||||
val refToConsumingTXMap = hashMapOf<ContractStateRef, LedgerTransaction>()
|
val refToConsumingTXMap = hashMapOf<StateRef, LedgerTransaction>()
|
||||||
|
|
||||||
val resolved = HashSet<TransactionForVerification>(transactions.size)
|
val resolved = HashSet<TransactionForVerification>(transactions.size)
|
||||||
for (tx in transactions) {
|
for (tx in transactions) {
|
||||||
|
@ -51,7 +51,7 @@ import java.util.*
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/** Transaction ready for serialisation, without any signatures attached. */
|
/** Transaction ready for serialisation, without any signatures attached. */
|
||||||
data class WireTransaction(val inputStates: List<ContractStateRef>,
|
data class WireTransaction(val inputStates: List<StateRef>,
|
||||||
val outputStates: List<ContractState>,
|
val outputStates: List<ContractState>,
|
||||||
val commands: List<Command>) {
|
val commands: List<Command>) {
|
||||||
fun toLedgerTransaction(identityService: IdentityService, originalHash: SecureHash): LedgerTransaction {
|
fun toLedgerTransaction(identityService: IdentityService, originalHash: SecureHash): LedgerTransaction {
|
||||||
@ -124,7 +124,7 @@ data class SignedWireTransaction(val txBits: SerializedBytes<WireTransaction>, v
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** A mutable transaction that's in the process of being built, before all signatures are present. */
|
/** A mutable transaction that's in the process of being built, before all signatures are present. */
|
||||||
class TransactionBuilder(private val inputStates: MutableList<ContractStateRef> = arrayListOf(),
|
class TransactionBuilder(private val inputStates: MutableList<StateRef> = arrayListOf(),
|
||||||
private val outputStates: MutableList<ContractState> = arrayListOf(),
|
private val outputStates: MutableList<ContractState> = arrayListOf(),
|
||||||
private val commands: MutableList<Command> = arrayListOf()) {
|
private val commands: MutableList<Command> = arrayListOf()) {
|
||||||
|
|
||||||
@ -152,7 +152,7 @@ class TransactionBuilder(private val inputStates: MutableList<ContractStateRef>
|
|||||||
public fun withItems(vararg items: Any): TransactionBuilder {
|
public fun withItems(vararg items: Any): TransactionBuilder {
|
||||||
for (t in items) {
|
for (t in items) {
|
||||||
when (t) {
|
when (t) {
|
||||||
is ContractStateRef -> inputStates.add(t)
|
is StateRef -> inputStates.add(t)
|
||||||
is ContractState -> outputStates.add(t)
|
is ContractState -> outputStates.add(t)
|
||||||
is Command -> commands.add(t)
|
is Command -> commands.add(t)
|
||||||
else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
|
else -> throw IllegalArgumentException("Wrong argument type: ${t.javaClass}")
|
||||||
@ -224,7 +224,7 @@ class TransactionBuilder(private val inputStates: MutableList<ContractStateRef>
|
|||||||
return SignedWireTransaction(toWireTransaction().serialize(), ArrayList(currentSigs))
|
return SignedWireTransaction(toWireTransaction().serialize(), ArrayList(currentSigs))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addInputState(ref: ContractStateRef) {
|
fun addInputState(ref: StateRef) {
|
||||||
check(currentSigs.isEmpty())
|
check(currentSigs.isEmpty())
|
||||||
inputStates.add(ref)
|
inputStates.add(ref)
|
||||||
}
|
}
|
||||||
@ -245,7 +245,7 @@ class TransactionBuilder(private val inputStates: MutableList<ContractStateRef>
|
|||||||
fun addCommand(data: CommandData, keys: List<PublicKey>) = addCommand(Command(data, keys))
|
fun addCommand(data: CommandData, keys: List<PublicKey>) = addCommand(Command(data, keys))
|
||||||
|
|
||||||
// Accessors that yield immutable snapshots.
|
// Accessors that yield immutable snapshots.
|
||||||
fun inputStates(): List<ContractStateRef> = ArrayList(inputStates)
|
fun inputStates(): List<StateRef> = ArrayList(inputStates)
|
||||||
fun outputStates(): List<ContractState> = ArrayList(outputStates)
|
fun outputStates(): List<ContractState> = ArrayList(outputStates)
|
||||||
fun commands(): List<Command> = ArrayList(commands)
|
fun commands(): List<Command> = ArrayList(commands)
|
||||||
}
|
}
|
||||||
@ -256,17 +256,17 @@ class TransactionBuilder(private val inputStates: MutableList<ContractStateRef>
|
|||||||
* with the commands from the wire, and verified/looked up.
|
* with the commands from the wire, and verified/looked up.
|
||||||
*/
|
*/
|
||||||
data class LedgerTransaction(
|
data class LedgerTransaction(
|
||||||
/** The input states which will be consumed/invalidated by the execution of this transaction. */
|
/** The input states which will be consumed/invalidated by the execution of this transaction. */
|
||||||
val inStateRefs: List<ContractStateRef>,
|
val inStateRefs: List<StateRef>,
|
||||||
/** The states that will be generated by the execution of this transaction. */
|
/** The states that will be generated by the execution of this transaction. */
|
||||||
val outStates: List<ContractState>,
|
val outStates: List<ContractState>,
|
||||||
/** Arbitrary data passed to the program of each input state. */
|
/** Arbitrary data passed to the program of each input state. */
|
||||||
val commands: List<AuthenticatedObject<CommandData>>,
|
val commands: List<AuthenticatedObject<CommandData>>,
|
||||||
/** The hash of the original serialised SignedTransaction */
|
/** The hash of the original serialised SignedTransaction */
|
||||||
val hash: SecureHash
|
val hash: SecureHash
|
||||||
) {
|
) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
fun <T : ContractState> outRef(index: Int) = StateAndRef(outStates[index] as T, ContractStateRef(hash, index))
|
fun <T : ContractState> outRef(index: Int) = StateAndRef(outStates[index] as T, StateRef(hash, index))
|
||||||
|
|
||||||
fun <T : ContractState> outRef(state: T): StateAndRef<T> {
|
fun <T : ContractState> outRef(state: T): StateAndRef<T> {
|
||||||
val i = outStates.indexOf(state)
|
val i = outStates.indexOf(state)
|
||||||
|
@ -53,14 +53,14 @@ class E2ETestWalletService(private val services: ServiceHub) : WalletService {
|
|||||||
|
|
||||||
val issuance = TransactionBuilder()
|
val issuance = TransactionBuilder()
|
||||||
val freshKey = services.keyManagementService.freshKey()
|
val freshKey = services.keyManagementService.freshKey()
|
||||||
cash.craftIssue(issuance, Amount(pennies, howMuch.currency), depositRef, freshKey.public)
|
cash.generateIssue(issuance, Amount(pennies, howMuch.currency), depositRef, freshKey.public)
|
||||||
issuance.signWith(myKey)
|
issuance.signWith(myKey)
|
||||||
|
|
||||||
return@map issuance.toSignedTransaction(true)
|
return@map issuance.toSignedTransaction(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val statesAndRefs = transactions.map {
|
val statesAndRefs = transactions.map {
|
||||||
StateAndRef(it.tx.outputStates[0] as OwnableState, ContractStateRef(it.id, 0))
|
StateAndRef(it.tx.outputStates[0] as OwnableState, StateRef(it.id, 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex.locked {
|
mutex.locked {
|
||||||
|
@ -178,7 +178,7 @@ fun makeFakeCommercialPaper(ownedBy: PublicKey): StateAndRef<CommercialPaper.Sta
|
|||||||
val party = Party("MegaCorp, Inc", KeyPairGenerator.getInstance("EC").genKeyPair().public)
|
val party = Party("MegaCorp, Inc", KeyPairGenerator.getInstance("EC").genKeyPair().public)
|
||||||
// ownedBy here is the random key that gives us control over it.
|
// ownedBy here is the random key that gives us control over it.
|
||||||
val paper = CommercialPaper.State(party.ref(1,2,3), ownedBy, 1100.DOLLARS, Instant.now() + 10.days)
|
val paper = CommercialPaper.State(party.ref(1,2,3), ownedBy, 1100.DOLLARS, Instant.now() + 10.days)
|
||||||
val randomRef = ContractStateRef(SecureHash.randomSHA256(), 0)
|
val randomRef = StateRef(SecureHash.randomSHA256(), 0)
|
||||||
return StateAndRef(paper, randomRef)
|
return StateAndRef(paper, randomRef)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ class CashTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val ptx = TransactionBuilder()
|
val ptx = TransactionBuilder()
|
||||||
Cash().craftIssue(ptx, 100.DOLLARS, MINI_CORP.ref(12,34), owner = DUMMY_PUBKEY_1)
|
Cash().generateIssue(ptx, 100.DOLLARS, MINI_CORP.ref(12,34), owner = DUMMY_PUBKEY_1)
|
||||||
assertTrue(ptx.inputStates().isEmpty())
|
assertTrue(ptx.inputStates().isEmpty())
|
||||||
val s = ptx.outputStates()[0] as Cash.State
|
val s = ptx.outputStates()[0] as Cash.State
|
||||||
assertEquals(100.DOLLARS, s.amount)
|
assertEquals(100.DOLLARS, s.amount)
|
||||||
@ -293,7 +293,7 @@ class CashTests {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
// Spend crafting
|
// Spend tx generation
|
||||||
|
|
||||||
val OUR_PUBKEY_1 = DUMMY_PUBKEY_1
|
val OUR_PUBKEY_1 = DUMMY_PUBKEY_1
|
||||||
val THEIR_PUBKEY_1 = DUMMY_PUBKEY_2
|
val THEIR_PUBKEY_1 = DUMMY_PUBKEY_2
|
||||||
@ -301,7 +301,7 @@ class CashTests {
|
|||||||
fun makeCash(amount: Amount, corp: Party, depositRef: Byte = 1) =
|
fun makeCash(amount: Amount, corp: Party, depositRef: Byte = 1) =
|
||||||
StateAndRef(
|
StateAndRef(
|
||||||
Cash.State(corp.ref(depositRef), amount, OUR_PUBKEY_1),
|
Cash.State(corp.ref(depositRef), amount, OUR_PUBKEY_1),
|
||||||
ContractStateRef(SecureHash.randomSHA256(), Random().nextInt(32))
|
StateRef(SecureHash.randomSHA256(), Random().nextInt(32))
|
||||||
)
|
)
|
||||||
|
|
||||||
val WALLET = listOf(
|
val WALLET = listOf(
|
||||||
@ -313,12 +313,12 @@ class CashTests {
|
|||||||
|
|
||||||
fun makeSpend(amount: Amount, dest: PublicKey): WireTransaction {
|
fun makeSpend(amount: Amount, dest: PublicKey): WireTransaction {
|
||||||
val tx = TransactionBuilder()
|
val tx = TransactionBuilder()
|
||||||
Cash().craftSpend(tx, amount, dest, WALLET)
|
Cash().generateSpend(tx, amount, dest, WALLET)
|
||||||
return tx.toWireTransaction()
|
return tx.toWireTransaction()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun craftSimpleDirectSpend() {
|
fun generateSimpleDirectSpend() {
|
||||||
val wtx = makeSpend(100.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(100.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
||||||
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1), wtx.outputStates[0])
|
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1), wtx.outputStates[0])
|
||||||
@ -326,14 +326,14 @@ class CashTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun craftSimpleSpendWithParties() {
|
fun generateSimpleSpendWithParties() {
|
||||||
val tx = TransactionBuilder()
|
val tx = TransactionBuilder()
|
||||||
Cash().craftSpend(tx, 80.DOLLARS, ALICE, WALLET, setOf(MINI_CORP))
|
Cash().generateSpend(tx, 80.DOLLARS, ALICE, WALLET, setOf(MINI_CORP))
|
||||||
assertEquals(WALLET[2].ref, tx.inputStates()[0])
|
assertEquals(WALLET[2].ref, tx.inputStates()[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun craftSimpleSpendWithChange() {
|
fun generateSimpleSpendWithChange() {
|
||||||
val wtx = makeSpend(10.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(10.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
||||||
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 10.DOLLARS), wtx.outputStates[0])
|
assertEquals(WALLET[0].state.copy(owner = THEIR_PUBKEY_1, amount = 10.DOLLARS), wtx.outputStates[0])
|
||||||
@ -342,7 +342,7 @@ class CashTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun craftSpendWithTwoInputs() {
|
fun generateSpendWithTwoInputs() {
|
||||||
val wtx = makeSpend(500.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(500.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
||||||
assertEquals(WALLET[1].ref, wtx.inputStates[1])
|
assertEquals(WALLET[1].ref, wtx.inputStates[1])
|
||||||
@ -351,7 +351,7 @@ class CashTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun craftSpendMixedDeposits() {
|
fun generateSpendMixedDeposits() {
|
||||||
val wtx = makeSpend(580.DOLLARS, THEIR_PUBKEY_1)
|
val wtx = makeSpend(580.DOLLARS, THEIR_PUBKEY_1)
|
||||||
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
assertEquals(WALLET[0].ref, wtx.inputStates[0])
|
||||||
assertEquals(WALLET[1].ref, wtx.inputStates[1])
|
assertEquals(WALLET[1].ref, wtx.inputStates[1])
|
||||||
@ -362,7 +362,7 @@ class CashTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun craftSpendInsufficientBalance() {
|
fun generateSpendInsufficientBalance() {
|
||||||
val e: InsufficientBalanceException = assertFailsWith("balance") {
|
val e: InsufficientBalanceException = assertFailsWith("balance") {
|
||||||
makeSpend(1000.DOLLARS, THEIR_PUBKEY_1)
|
makeSpend(1000.DOLLARS, THEIR_PUBKEY_1)
|
||||||
}
|
}
|
||||||
|
@ -115,7 +115,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
fun `timestamp out of range`() {
|
fun `timestamp out of range`() {
|
||||||
// Check what happens if the timestamp on the transaction itself defines a range that doesn't include true
|
// Check what happens if the timestamp on the transaction itself defines a range that doesn't include true
|
||||||
// time as measured by a TSA (which is running five hours ahead in this test).
|
// time as measured by a TSA (which is running five hours ahead in this test).
|
||||||
CommercialPaper().craftIssue(MINI_CORP.ref(123), 10000.DOLLARS, TEST_TX_TIME + 30.days).apply {
|
CommercialPaper().generateIssue(MINI_CORP.ref(123), 10000.DOLLARS, TEST_TX_TIME + 30.days).apply {
|
||||||
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
||||||
signWith(MINI_CORP_KEY)
|
signWith(MINI_CORP_KEY)
|
||||||
assertFailsWith(TimestampingError.NotOnTimeException::class) {
|
assertFailsWith(TimestampingError.NotOnTimeException::class) {
|
||||||
@ -123,7 +123,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check that it also fails if true time is before the threshold (we are trying to timestamp too early).
|
// Check that it also fails if true time is before the threshold (we are trying to timestamp too early).
|
||||||
CommercialPaper().craftIssue(MINI_CORP.ref(123), 10000.DOLLARS, TEST_TX_TIME + 30.days).apply {
|
CommercialPaper().generateIssue(MINI_CORP.ref(123), 10000.DOLLARS, TEST_TX_TIME + 30.days).apply {
|
||||||
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
||||||
signWith(MINI_CORP_KEY)
|
signWith(MINI_CORP_KEY)
|
||||||
assertFailsWith(TimestampingError.NotOnTimeException::class) {
|
assertFailsWith(TimestampingError.NotOnTimeException::class) {
|
||||||
@ -162,14 +162,14 @@ class CommercialPaperTestsGeneric {
|
|||||||
|
|
||||||
fun cashOutputsToWallet(vararg states: Cash.State): Pair<LedgerTransaction, List<StateAndRef<Cash.State>>> {
|
fun cashOutputsToWallet(vararg states: Cash.State): Pair<LedgerTransaction, List<StateAndRef<Cash.State>>> {
|
||||||
val ltx = LedgerTransaction(emptyList(), listOf(*states), emptyList(), SecureHash.randomSHA256())
|
val ltx = LedgerTransaction(emptyList(), listOf(*states), emptyList(), SecureHash.randomSHA256())
|
||||||
return Pair(ltx, states.mapIndexed { index, state -> StateAndRef(state, ContractStateRef(ltx.hash, index)) })
|
return Pair(ltx, states.mapIndexed { index, state -> StateAndRef(state, StateRef(ltx.hash, index)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `issue move and then redeem`() {
|
fun `issue move and then redeem`() {
|
||||||
// MiniCorp issues $10,000 of commercial paper, to mature in 30 days, owned initially by itself.
|
// MiniCorp issues $10,000 of commercial paper, to mature in 30 days, owned initially by itself.
|
||||||
val issueTX: LedgerTransaction = run {
|
val issueTX: LedgerTransaction = run {
|
||||||
val ptx = CommercialPaper().craftIssue(MINI_CORP.ref(123), 10000.DOLLARS, TEST_TX_TIME + 30.days).apply {
|
val ptx = CommercialPaper().generateIssue(MINI_CORP.ref(123), 10000.DOLLARS, TEST_TX_TIME + 30.days).apply {
|
||||||
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
||||||
signWith(MINI_CORP_KEY)
|
signWith(MINI_CORP_KEY)
|
||||||
timestamp(DUMMY_TIMESTAMPER)
|
timestamp(DUMMY_TIMESTAMPER)
|
||||||
@ -187,8 +187,8 @@ class CommercialPaperTestsGeneric {
|
|||||||
// Alice pays $9000 to MiniCorp to own some of their debt.
|
// Alice pays $9000 to MiniCorp to own some of their debt.
|
||||||
val moveTX: LedgerTransaction = run {
|
val moveTX: LedgerTransaction = run {
|
||||||
val ptx = TransactionBuilder()
|
val ptx = TransactionBuilder()
|
||||||
Cash().craftSpend(ptx, 9000.DOLLARS, MINI_CORP_PUBKEY, alicesWallet)
|
Cash().generateSpend(ptx, 9000.DOLLARS, MINI_CORP_PUBKEY, alicesWallet)
|
||||||
CommercialPaper().craftMove(ptx, issueTX.outRef(0), ALICE)
|
CommercialPaper().generateMove(ptx, issueTX.outRef(0), ALICE)
|
||||||
ptx.signWith(MINI_CORP_KEY)
|
ptx.signWith(MINI_CORP_KEY)
|
||||||
ptx.signWith(ALICE_KEY)
|
ptx.signWith(ALICE_KEY)
|
||||||
val stx = ptx.toSignedTransaction()
|
val stx = ptx.toSignedTransaction()
|
||||||
@ -204,7 +204,7 @@ class CommercialPaperTestsGeneric {
|
|||||||
fun makeRedeemTX(time: Instant): LedgerTransaction {
|
fun makeRedeemTX(time: Instant): LedgerTransaction {
|
||||||
val ptx = TransactionBuilder()
|
val ptx = TransactionBuilder()
|
||||||
ptx.setTime(time, DummyTimestampingAuthority.identity, 30.seconds)
|
ptx.setTime(time, DummyTimestampingAuthority.identity, 30.seconds)
|
||||||
CommercialPaper().craftRedeem(ptx, moveTX.outRef(1), corpWallet)
|
CommercialPaper().generateRedeem(ptx, moveTX.outRef(1), corpWallet)
|
||||||
ptx.signWith(ALICE_KEY)
|
ptx.signWith(ALICE_KEY)
|
||||||
ptx.signWith(MINI_CORP_KEY)
|
ptx.signWith(MINI_CORP_KEY)
|
||||||
ptx.timestamp(DUMMY_TIMESTAMPER)
|
ptx.timestamp(DUMMY_TIMESTAMPER)
|
||||||
|
@ -99,7 +99,7 @@ class CrowdFundTests {
|
|||||||
|
|
||||||
fun cashOutputsToWallet(vararg states: Cash.State): Pair<LedgerTransaction, List<StateAndRef<Cash.State>>> {
|
fun cashOutputsToWallet(vararg states: Cash.State): Pair<LedgerTransaction, List<StateAndRef<Cash.State>>> {
|
||||||
val ltx = LedgerTransaction(emptyList(), listOf(*states), emptyList(), SecureHash.randomSHA256())
|
val ltx = LedgerTransaction(emptyList(), listOf(*states), emptyList(), SecureHash.randomSHA256())
|
||||||
return Pair(ltx, states.mapIndexed { index, state -> StateAndRef(state, ContractStateRef(ltx.hash, index)) })
|
return Pair(ltx, states.mapIndexed { index, state -> StateAndRef(state, StateRef(ltx.hash, index)) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -107,7 +107,7 @@ class CrowdFundTests {
|
|||||||
// MiniCorp registers a crowdfunding of $1,000, to close in 7 days.
|
// MiniCorp registers a crowdfunding of $1,000, to close in 7 days.
|
||||||
val registerTX: LedgerTransaction = run {
|
val registerTX: LedgerTransaction = run {
|
||||||
// craftRegister returns a partial transaction
|
// craftRegister returns a partial transaction
|
||||||
val ptx = CrowdFund().craftRegister(MINI_CORP.ref(123), 1000.DOLLARS, "crowd funding", TEST_TX_TIME + 7.days).apply {
|
val ptx = CrowdFund().generateRegister(MINI_CORP.ref(123), 1000.DOLLARS, "crowd funding", TEST_TX_TIME + 7.days).apply {
|
||||||
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
||||||
signWith(MINI_CORP_KEY)
|
signWith(MINI_CORP_KEY)
|
||||||
timestamp(DUMMY_TIMESTAMPER)
|
timestamp(DUMMY_TIMESTAMPER)
|
||||||
@ -126,8 +126,8 @@ class CrowdFundTests {
|
|||||||
// Alice pays $1000 to MiniCorp to fund their campaign.
|
// Alice pays $1000 to MiniCorp to fund their campaign.
|
||||||
val pledgeTX: LedgerTransaction = run {
|
val pledgeTX: LedgerTransaction = run {
|
||||||
val ptx = TransactionBuilder()
|
val ptx = TransactionBuilder()
|
||||||
CrowdFund().craftPledge(ptx, registerTX.outRef(0), ALICE)
|
CrowdFund().generatePledge(ptx, registerTX.outRef(0), ALICE)
|
||||||
Cash().craftSpend(ptx, 1000.DOLLARS, MINI_CORP_PUBKEY, aliceWallet)
|
Cash().generateSpend(ptx, 1000.DOLLARS, MINI_CORP_PUBKEY, aliceWallet)
|
||||||
ptx.setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
ptx.setTime(TEST_TX_TIME, DummyTimestampingAuthority.identity, 30.seconds)
|
||||||
ptx.signWith(ALICE_KEY)
|
ptx.signWith(ALICE_KEY)
|
||||||
ptx.timestamp(DUMMY_TIMESTAMPER)
|
ptx.timestamp(DUMMY_TIMESTAMPER)
|
||||||
@ -145,7 +145,7 @@ class CrowdFundTests {
|
|||||||
fun makeFundedTX(time: Instant): LedgerTransaction {
|
fun makeFundedTX(time: Instant): LedgerTransaction {
|
||||||
val ptx = TransactionBuilder()
|
val ptx = TransactionBuilder()
|
||||||
ptx.setTime(time, DUMMY_TIMESTAMPER.identity, 30.seconds)
|
ptx.setTime(time, DUMMY_TIMESTAMPER.identity, 30.seconds)
|
||||||
CrowdFund().craftClose(ptx, pledgeTX.outRef(0), miniCorpWallet)
|
CrowdFund().generateClose(ptx, pledgeTX.outRef(0), miniCorpWallet)
|
||||||
ptx.signWith(MINI_CORP_KEY)
|
ptx.signWith(MINI_CORP_KEY)
|
||||||
ptx.timestamp(DUMMY_TIMESTAMPER)
|
ptx.timestamp(DUMMY_TIMESTAMPER)
|
||||||
val stx = ptx.toSignedTransaction()
|
val stx = ptx.toSignedTransaction()
|
||||||
|
@ -73,7 +73,7 @@ class TransactionGroupTests {
|
|||||||
val e = assertFailsWith(TransactionConflictException::class) {
|
val e = assertFailsWith(TransactionConflictException::class) {
|
||||||
verify()
|
verify()
|
||||||
}
|
}
|
||||||
assertEquals(ContractStateRef(t.hash, 0), e.conflictRef)
|
assertEquals(StateRef(t.hash, 0), e.conflictRef)
|
||||||
assertEquals(setOf(conflict1, conflict2), setOf(e.tx1, e.tx2))
|
assertEquals(setOf(conflict1, conflict2), setOf(e.tx1, e.tx2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +95,7 @@ class TransactionGroupTests {
|
|||||||
|
|
||||||
// We have to do this manually without the DSL because transactionGroup { } won't let us create a tx that
|
// We have to do this manually without the DSL because transactionGroup { } won't let us create a tx that
|
||||||
// points nowhere.
|
// points nowhere.
|
||||||
val ref = ContractStateRef(SecureHash.randomSHA256(), 0)
|
val ref = StateRef(SecureHash.randomSHA256(), 0)
|
||||||
tg.txns.add(LedgerTransaction(
|
tg.txns.add(LedgerTransaction(
|
||||||
listOf(ref), listOf(A_THOUSAND_POUNDS), listOf(AuthenticatedObject(listOf(BOB), emptyList(), Cash.Commands.Move())), SecureHash.randomSHA256())
|
listOf(ref), listOf(A_THOUSAND_POUNDS), listOf(AuthenticatedObject(listOf(BOB), emptyList(), Cash.Commands.Move())), SecureHash.randomSHA256())
|
||||||
)
|
)
|
||||||
|
@ -31,7 +31,7 @@ class TimestamperNodeServiceTest : TestWithInMemoryNetwork() {
|
|||||||
lateinit var service: TimestamperNodeService
|
lateinit var service: TimestamperNodeService
|
||||||
|
|
||||||
val ptx = TransactionBuilder().apply {
|
val ptx = TransactionBuilder().apply {
|
||||||
addInputState(ContractStateRef(SecureHash.randomSHA256(), 0))
|
addInputState(StateRef(SecureHash.randomSHA256(), 0))
|
||||||
addOutputState(100.DOLLARS.CASH)
|
addOutputState(100.DOLLARS.CASH)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ class TimestamperNodeServiceTest : TestWithInMemoryNetwork() {
|
|||||||
override fun call(): Boolean {
|
override fun call(): Boolean {
|
||||||
val client = TimestamperClient(this, server)
|
val client = TimestamperClient(this, server)
|
||||||
val ptx = TransactionBuilder().apply {
|
val ptx = TransactionBuilder().apply {
|
||||||
addInputState(ContractStateRef(SecureHash.randomSHA256(), 0))
|
addInputState(StateRef(SecureHash.randomSHA256(), 0))
|
||||||
addOutputState(100.DOLLARS.CASH)
|
addOutputState(100.DOLLARS.CASH)
|
||||||
}
|
}
|
||||||
ptx.addCommand(TimestampCommand(now - 20.seconds, now + 20.seconds), server.identity.owningKey)
|
ptx.addCommand(TimestampCommand(now - 20.seconds, now + 20.seconds), server.identity.owningKey)
|
||||||
|
@ -24,7 +24,7 @@ class TransactionSerializationTests {
|
|||||||
val outputState = Cash.State(depositRef, 600.POUNDS, DUMMY_PUBKEY_1)
|
val outputState = Cash.State(depositRef, 600.POUNDS, DUMMY_PUBKEY_1)
|
||||||
val changeState = Cash.State(depositRef, 400.POUNDS, TestUtils.keypair.public)
|
val changeState = Cash.State(depositRef, 400.POUNDS, TestUtils.keypair.public)
|
||||||
|
|
||||||
val fakeStateRef = ContractStateRef(SecureHash.sha256("fake tx id"), 0)
|
val fakeStateRef = StateRef(SecureHash.sha256("fake tx id"), 0)
|
||||||
lateinit var tx: TransactionBuilder
|
lateinit var tx: TransactionBuilder
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -201,7 +201,7 @@ fun transaction(body: TransactionForTest.() -> Unit) = TransactionForTest().appl
|
|||||||
|
|
||||||
class TransactionGroupDSL<T : ContractState>(private val stateType: Class<T>) {
|
class TransactionGroupDSL<T : ContractState>(private val stateType: Class<T>) {
|
||||||
open inner class LedgerTransactionDSL : AbstractTransactionForTest() {
|
open inner class LedgerTransactionDSL : AbstractTransactionForTest() {
|
||||||
private val inStates = ArrayList<ContractStateRef>()
|
private val inStates = ArrayList<StateRef>()
|
||||||
|
|
||||||
fun input(label: String) {
|
fun input(label: String) {
|
||||||
inStates.add(label.outputRef)
|
inStates.add(label.outputRef)
|
||||||
@ -219,7 +219,7 @@ class TransactionGroupDSL<T : ContractState>(private val stateType: Class<T>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val String.output: T get() = labelToOutputs[this] ?: throw IllegalArgumentException("State with label '$this' was not found")
|
val String.output: T get() = labelToOutputs[this] ?: throw IllegalArgumentException("State with label '$this' was not found")
|
||||||
val String.outputRef: ContractStateRef get() = labelToRefs[this] ?: throw IllegalArgumentException("Unknown label \"$this\"")
|
val String.outputRef: StateRef get() = labelToRefs[this] ?: throw IllegalArgumentException("Unknown label \"$this\"")
|
||||||
|
|
||||||
fun <C : ContractState> lookup(label: String) = StateAndRef(label.output as C, label.outputRef)
|
fun <C : ContractState> lookup(label: String) = StateAndRef(label.output as C, label.outputRef)
|
||||||
|
|
||||||
@ -228,7 +228,7 @@ class TransactionGroupDSL<T : ContractState>(private val stateType: Class<T>) {
|
|||||||
val ltx = toLedgerTransaction()
|
val ltx = toLedgerTransaction()
|
||||||
for ((index, labelledState) in outStates.withIndex()) {
|
for ((index, labelledState) in outStates.withIndex()) {
|
||||||
if (labelledState.label != null) {
|
if (labelledState.label != null) {
|
||||||
labelToRefs[labelledState.label] = ContractStateRef(ltx.hash, index)
|
labelToRefs[labelledState.label] = StateRef(ltx.hash, index)
|
||||||
if (stateType.isInstance(labelledState.state)) {
|
if (stateType.isInstance(labelledState.state)) {
|
||||||
labelToOutputs[labelledState.label] = labelledState.state as T
|
labelToOutputs[labelledState.label] = labelledState.state as T
|
||||||
}
|
}
|
||||||
@ -240,7 +240,7 @@ class TransactionGroupDSL<T : ContractState>(private val stateType: Class<T>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val rootTxns = ArrayList<LedgerTransaction>()
|
private val rootTxns = ArrayList<LedgerTransaction>()
|
||||||
private val labelToRefs = HashMap<String, ContractStateRef>()
|
private val labelToRefs = HashMap<String, StateRef>()
|
||||||
private val labelToOutputs = HashMap<String, T>()
|
private val labelToOutputs = HashMap<String, T>()
|
||||||
private val outputsToLabels = HashMap<ContractState, String>()
|
private val outputsToLabels = HashMap<ContractState, String>()
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ class TransactionGroupDSL<T : ContractState>(private val stateType: Class<T>) {
|
|||||||
val ltx = wtx.toLedgerTransaction(MockIdentityService, SecureHash.randomSHA256())
|
val ltx = wtx.toLedgerTransaction(MockIdentityService, SecureHash.randomSHA256())
|
||||||
for ((index, state) in outputStates.withIndex()) {
|
for ((index, state) in outputStates.withIndex()) {
|
||||||
val label = state.label!!
|
val label = state.label!!
|
||||||
labelToRefs[label] = ContractStateRef(ltx.hash, index)
|
labelToRefs[label] = StateRef(ltx.hash, index)
|
||||||
outputsToLabels[state.state] = label
|
outputsToLabels[state.state] = label
|
||||||
labelToOutputs[label] = state.state as T
|
labelToOutputs[label] = state.state as T
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user