@@ -15,7 +15,8 @@ import net.corda.core.utilities.getOrThrow
15
15
import net.corda.finance.contracts.Commodity
16
16
import net.corda.finance.contracts.DealState
17
17
import net.corda.finance.contracts.asset.Cash
18
- import net.corda.finance.contracts.asset.CommodityContract
18
+ import net.corda.finance.contracts.asset.Obligation
19
+ import net.corda.finance.contracts.asset.OnLedgerAsset
19
20
import net.corda.testing.core.*
20
21
import net.corda.testing.internal.chooseIdentity
21
22
import net.corda.testing.internal.chooseIdentityAndCert
@@ -166,19 +167,26 @@ class VaultFiller @JvmOverloads constructor(
166
167
return Vault (states)
167
168
}
168
169
170
+
171
+ /* *
172
+ * Puts together an issuance transaction for the specified amount that starts out being owned by the given pubkey.
173
+ */
174
+ fun generateCommoditiesIssue (tx : TransactionBuilder , amount : Amount <Issued <Commodity >>, owner : AbstractParty , notary : Party )
175
+ = OnLedgerAsset .generateIssue(tx, TransactionState (CommodityState (amount, owner), Obligation .PROGRAM_ID , notary), Obligation .Commands .Issue ())
176
+
177
+
169
178
/* *
170
179
*
171
180
* @param issuerServices service hub of the issuer node, which will be used to sign the transaction.
172
181
* @return a vault object that represents the generated states (it will NOT be the full vault from the service hub!).
173
182
*/
174
183
// TODO: need to make all FungibleAsset commands (issue, move, exit) generic
175
- fun fillWithSomeTestCommodity (amount : Amount <Commodity >, issuerServices : ServiceHub , issuedBy : PartyAndReference ): Vault <CommodityContract . State > {
184
+ fun fillWithSomeTestCommodity (amount : Amount <Commodity >, issuerServices : ServiceHub , issuedBy : PartyAndReference ): Vault <CommodityState > {
176
185
val myKey: PublicKey = services.myInfo.chooseIdentity().owningKey
177
186
val me = AnonymousParty (myKey)
178
187
179
- val commodity = CommodityContract ()
180
188
val issuance = TransactionBuilder (null as Party ? )
181
- commodity.generateIssue (issuance, Amount (amount.quantity, Issued (issuedBy, amount.token)), me, altNotary)
189
+ generateCommoditiesIssue (issuance, Amount (amount.quantity, Issued (issuedBy, amount.token)), me, altNotary)
182
190
val transaction = issuerServices.signInitialTransaction(issuance, issuedBy.party.owningKey)
183
191
services.recordTransactions(transaction)
184
192
return Vault (setOf (transaction.tx.outRef(0 )))
@@ -241,3 +249,27 @@ class VaultFiller @JvmOverloads constructor(
241
249
return update.getOrThrow(Duration .ofSeconds(3 ))
242
250
}
243
251
}
252
+
253
+
254
+
255
+ /* * A state representing a commodity claim against some party */
256
+ data class CommodityState (
257
+ override val amount : Amount <Issued <Commodity >>,
258
+
259
+ /* * There must be a MoveCommand signed by this key to claim the amount */
260
+ override val owner : AbstractParty
261
+ ) : FungibleAsset<Commodity> {
262
+ constructor (deposit: PartyAndReference , amount: Amount <Commodity >, owner: AbstractParty )
263
+ : this (Amount (amount.quantity, Issued (deposit, amount.token)), owner)
264
+
265
+ override val exitKeys: Set <PublicKey > = Collections .singleton(owner.owningKey)
266
+ override val participants = listOf (owner)
267
+
268
+ override fun withNewOwnerAndAmount (newAmount : Amount <Issued <Commodity >>, newOwner : AbstractParty ): FungibleAsset <Commodity >
269
+ = copy(amount = amount.copy(newAmount.quantity), owner = newOwner)
270
+
271
+ override fun toString () = " Commodity($amount at ${amount.token.issuer} owned by $owner )"
272
+
273
+ override fun withNewOwner (newOwner : AbstractParty ) = CommandAndState (Obligation .Commands .Move (), copy(owner = newOwner))
274
+ }
275
+
0 commit comments