Skip to content

Commit 47cfcf5

Browse files
author
ggobugi27
committed
require buyer_fungible_account at map-escrowed-buy
1 parent a56f400 commit 47cfcf5

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

pact/concrete-policies/royalty-policy/royalty-policy-v1.repl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"fungible": marmalade.abc
9292
,"price": 2.0
9393
,"amount": 1.0
94-
,"seller-account": {
94+
,"seller-fungible-account": {
9595
"account": "k:account"
9696
,"guard": {"keys": ["account"], "pred": "keys-all"}
9797
}
@@ -116,6 +116,7 @@
116116

117117
(env-data {
118118
"buyer": "k:buyer"
119+
,"buyer_fungible_account": "k:buyer"
119120
,"buyer-guard": {"keys": ["buyer"], "pred": "keys-all"}
120121
})
121122

pact/policy-manager/policy-manager.pact

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
(use kip.token-policy-v2 [token-info])
99
(use marmalade.quote-manager)
10-
(use marmalade.quote-manager [quote-spec quote-msg])
10+
(use marmalade.quote-manager [quote-spec quote-msg fungible-account])
1111

1212
(defconst QUOTE-MSG-KEY "quote"
1313
@doc "Payload field for quote spec")
1414

1515
(defconst UPDATE-QUOTE-PRICE-MSG-KEY "update_quote_price"
1616
@doc "Payload field for quote spec")
1717

18+
(defconst BUYER-FUNGIBLE-ACCOUNT-MSG-KEY "buyer_fungible_account"
19+
@doc "Payload field for buyer's fungible account")
20+
1821
(defcap POLICY_MANAGER:bool ()
1922
@doc "Ledger module guard for policies to be able to validate access to policy operations."
2023
true
@@ -246,12 +249,13 @@
246249
(quote:object{quote-schema} (get-quote-info sale-id))
247250
(spec:object{quote-spec} (at 'spec quote))
248251
(fungible:module{fungible-v2} (at 'fungible spec))
249-
(seller-account:object{fungible-account} (at 'seller-account spec))
252+
(buyer-fungible-account-name:string (read-msg BUYER-FUNGIBLE-ACCOUNT-MSG-KEY))
253+
(seller-fungible-account:object{fungible-account} (at 'seller-fungible-account spec))
250254
(price:decimal (at 'price spec))
251255
(sale-price:decimal (floor (* price amount) (fungible::precision)))
252256
)
253257
;; transfer fungible to escrow account
254-
(fungible::transfer-create buyer (at 'account escrow-account) (at 'guard escrow-account) sale-price)
258+
(fungible::transfer-create buyer-fungible-account-name (at 'account escrow-account) (at 'guard escrow-account) sale-price)
255259

256260
(with-capability (ESCROW sale-id)
257261
;; Run policies::enforce-buy
@@ -260,8 +264,8 @@
260264
(let (
261265
(balance:decimal (fungible::get-balance (at 'account escrow-account)))
262266
)
263-
(install-capability (fungible::TRANSFER (at 'account escrow-account) (at 'account seller-account) balance))
264-
(fungible::transfer (at 'account escrow-account) (at 'account seller-account) balance)
267+
(install-capability (fungible::TRANSFER (at 'account escrow-account) (at 'account seller-fungible-account) balance))
268+
(fungible::transfer (at 'account escrow-account) (at 'account seller-fungible-account) balance)
265269
)
266270
)
267271
true
@@ -284,7 +288,7 @@
284288
@doc "Checks env-data field and see if the msg is a object"
285289
(= (take 6 (typeof (try false (read-msg msg)))) "object")
286290
)
287-
291+
288292
(defun token-init (token:object{token-info} policy:module{kip.token-policy-v2})
289293
(policy::enforce-init token))
290294

pact/policy-manager/policy-manager.repl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
"fungible": marmalade.abc
262262
,"price": 2.0
263263
,"amount": 1.0
264-
,"seller-account": {
264+
,"seller-fungible-account": {
265265
"account": "k:account"
266266
,"guard": {"keys": ["account"], "pred": "keys-all"}
267267
}
@@ -293,7 +293,7 @@
293293
{"name": "marmalade.ledger.OFFER","params": [(read-msg 'token-id) "k:account" 1.0 "2023-07-22T11:26:35Z"]}
294294
{"name": "marmalade.ledger.SALE","params": [(read-msg 'token-id) "k:account" 1.0 "2023-07-22T11:26:35Z" "C1vw1eMf_DZV3oZjyinRIKrQV2rPMBMh3lydeduo8yg"]}
295295
{"name": "marmalade.quote-manager.QUOTE","params": ["C1vw1eMf_DZV3oZjyinRIKrQV2rPMBMh3lydeduo8yg" (read-msg 'token-id)
296-
{"amount": 1.0,"fungible": marmalade.abc,"price": 2.0,"seller-account": {"account": "k:account","guard": (read-keyset 'seller-guard) }}]}
296+
{"amount": 1.0,"fungible": marmalade.abc,"price": 2.0,"seller-fungible-account": {"account": "k:account","guard": (read-keyset 'seller-guard) }}]}
297297
{"name": "marmalade.quote-manager.QUOTE_GUARDS","params": ["C1vw1eMf_DZV3oZjyinRIKrQV2rPMBMh3lydeduo8yg" (read-msg 'token-id) (read-keyset 'seller-guard) []]}
298298
{"name": "marmalade.ledger.ACCOUNT_GUARD","params": [(read-msg 'token-id) "c:kojW5oDBdlmFg0jVWz_mdj1DxlL8OgeH-1OILa1YzzE" (create-capability-pact-guard (SALE_PRIVATE "C1vw1eMf_DZV3oZjyinRIKrQV2rPMBMh3lydeduo8yg"))]}
299299
{"name": "marmalade.ledger.TRANSFER","params": [(read-msg 'token-id) "k:account" "c:kojW5oDBdlmFg0jVWz_mdj1DxlL8OgeH-1OILa1YzzE" 1.0]}
@@ -302,9 +302,10 @@
302302
)
303303

304304
(env-data {
305-
"buyer": "k:buyer"
306-
,"buyer-guard": {"keys": ["buyer"], "pred": "keys-all"}
307-
,"market-guard": {"keys": ["market"], "pred": "keys-all"}
305+
"buyer_fungible_account": "k:buyer"
306+
,"buyer": "k:buyer"
307+
,"buyer-guard": {"keys": ["buyer"], "pred": "keys-all"}
308+
,"market-guard": {"keys": ["market"], "pred": "keys-all"}
308309
})
309310

310311
(marmalade.abc.create-account "k:buyer" (read-keyset 'buyer-guard))

pact/quote-manager/quote-manager.pact

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
(defschema quote-spec
4747
@doc "Quote spec of the sale"
4848
fungible:module{fungible-v2}
49-
seller-account:object{fungible-account}
49+
seller-fungible-account:object{fungible-account}
5050
price:decimal
5151
amount:decimal
5252
)
@@ -162,14 +162,14 @@
162162
(bind quote-spec {
163163
"fungible":= fungible
164164
,"amount":= amount
165-
,"seller-account":= fungible-account
165+
,"seller-fungible-account":= fungible-account
166166
}
167167
(update quotes sale-id {
168168
"spec": {
169169
"fungible": fungible
170170
, "amount": amount
171171
, "price": price
172-
, "seller-account": fungible-account
172+
, "seller-fungible-account": fungible-account
173173
}
174174
}))
175175
)
@@ -183,20 +183,20 @@
183183
)
184184

185185
;; Validate functions
186-
(defun validate-fungible-account (fungible:module{fungible-v2} seller-account:object{fungible-account})
187-
(let ((seller-details (fungible::details (at 'account seller-account))))
186+
(defun validate-fungible-account (fungible:module{fungible-v2} account:object{fungible-account})
187+
(let ((seller-details (fungible::details (at 'account account))))
188188
(enforce (=
189-
(at 'guard seller-details) (at 'guard seller-account))
190-
"Seller guard does not match"))
189+
(at 'guard seller-details) (at 'guard account))
190+
"Account guard does not match"))
191191
)
192192

193193
(defun validate-quote:bool (quote-spec:object{quote-spec})
194194
(let* ( (fungible:module{fungible-v2} (at 'fungible quote-spec) )
195-
(seller-account:object{fungible-account} (at 'seller-account quote-spec))
195+
(seller-fungible-account:object{fungible-account} (at 'seller-fungible-account quote-spec))
196196
(amount:decimal (at 'amount quote-spec))
197197
(price:decimal (at 'price quote-spec))
198198
(sale-price:decimal (* amount price)) )
199-
(validate-fungible-account fungible seller-account)
199+
(validate-fungible-account fungible seller-fungible-account)
200200
(fungible::enforce-unit sale-price)
201201
(enforce (< 0.0 price) "Offer price must be positive")
202202
true)

pact/quote-manager/quote-manager.repl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
}),
2929
"quote": {
3030
"spec": {
31-
"seller-account": {
31+
"seller-fungible-account": {
3232
"account": "k:account"
3333
,"guard": {"keys": ["account"], "pred": "keys-all"}
3434
}
@@ -112,6 +112,7 @@
112112
,"buyer-guard": {"keys": ["bidder"], "pred": "keys-all"}
113113
,"market-guard": {"keys": ["market"], "pred": "keys-all"}
114114
,"update_quote_price": 20.0
115+
,"buyer_fungible_account": "k:bidder"
115116
})
116117

117118
(env-sigs [

0 commit comments

Comments
 (0)