Skip to content

Commit 46a6247

Browse files
committed
dependency cleanup, naming consistency
1 parent fa26fec commit 46a6247

File tree

5 files changed

+81
-204
lines changed

5 files changed

+81
-204
lines changed

stacks/Clarinet.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ contract_id = 'SP1E0XBN9T4B10E9QMR7XMFJPMA19D77WY3KP2QKC.self-listing-helper-v3'
1111
path = 'contracts/executor-state.clar'
1212
clarity_version = 3
1313
epoch = 'latest'
14+
requirements = ['SP1E0XBN9T4B10E9QMR7XMFJPMA19D77WY3KP2QKC.self-listing-helper-v3']
1415

1516
[contracts.executor]
1617
path = 'contracts/executor.clar'

stacks/contracts/executor-state.clar

Lines changed: 14 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,32 @@
1010

1111
;;;; Data maps
1212

13-
;; Map to track relayer addresses for payments
13+
;; Map to track payee addresses for payments
1414
;; Universal address is keccak256(stacks-principal-as-string)
15-
(define-map relayer-to-stacks
15+
(define-map universal-address-to-principal
1616
(buff 32) ;; Universal address (32-byte hash)
1717
principal ;; Stacks principal for STX payments
1818
)
1919

2020
;;;; Public functions
2121

22-
;; @desc Register a relayer's Stacks address for their universal address
23-
;; Anyone can call this to register themselves as a relayer
24-
(define-public (register-relayer (stacks-addr principal))
22+
;; @desc Register a payee's Stacks address for their universal address
23+
;; Anyone can call this to register themselves as a payee
24+
(define-public (register-payee (stacks-addr principal))
2525
(let (
26-
(p-as-string (principal-to-string stacks-addr))
26+
(p-as-string (contract-call?
27+
'SP1E0XBN9T4B10E9QMR7XMFJPMA19D77WY3KP2QKC.self-listing-helper-v3
28+
principal-to-string stacks-addr
29+
))
2730
(universal-addr (keccak256 (string-ascii-to-buff p-as-string)))
2831
)
29-
;; Check if relayer already exists
30-
(asserts! (is-none (relayer-to-stacks-get universal-addr))
32+
;; Check if payee already exists
33+
(asserts! (is-none (universal-address-to-principal-get universal-addr))
3134
ERR_STATE_RELAYER_EXISTS
3235
)
3336

3437
;; Register the mapping
35-
(map-set relayer-to-stacks universal-addr stacks-addr)
38+
(map-set universal-address-to-principal universal-addr stacks-addr)
3639

3740
;; Return the universal address for confirmation
3841
(ok universal-addr)
@@ -41,11 +44,6 @@
4144

4245
;;;; Read-only functions
4346

44-
;; @desc Convert universal address to Stacks principal
45-
(define-read-only (universal-addr-to-principal (universal-addr (buff 32)))
46-
(relayer-to-stacks-get universal-addr)
47-
)
48-
4947
;; @desc Helper function to convert string to buffer for hashing
5048
;; Matches the exact implementation from Wormhole Core
5149
(define-read-only (string-ascii-to-buff (s (string-ascii 256)))
@@ -58,115 +56,8 @@
5856
)
5957
)
6058

61-
;; principle to string conversion from https://explorer.hiro.so/txid/0xa0988bb5f2aa6179e61e7735b91f7276cf70106f05781a0c1c7dee663be5dc7c?chain=mainnet
62-
;; @desc Convert principal to string representation (C32 encoding)
63-
(define-read-only (principal-to-string (p principal))
64-
(let (
65-
(destructed (unwrap-panic (principal-destruct? p)))
66-
(checksum (unwrap-panic (slice?
67-
(sha256 (sha256 (concat (get version destructed) (get hash-bytes destructed))))
68-
u0 u4
69-
)))
70-
(data (unwrap-panic (as-max-len? (concat (get hash-bytes destructed) checksum) u24)))
71-
(result (concat
72-
(concat "S"
73-
(unwrap-panic (element-at? C32 (buff-to-uint-be (get version destructed))))
74-
)
75-
(append-leading-0 data (trim-leading-0 (hash-bytes-to-string data)))
76-
))
77-
)
78-
(match (get name destructed)
79-
n (concat (concat result ".") n)
80-
result
81-
)
82-
)
83-
)
84-
85-
;; Constants and helpers for C32 encoding
86-
(define-constant C32 "0123456789ABCDEFGHJKMNPQRSTVWXYZ")
87-
(define-constant LIST_15 (list 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
88-
(define-constant LIST_24 (list 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0))
89-
(define-constant LIST_39 (concat LIST_24 LIST_15))
90-
91-
(define-read-only (c32-to-string-iter
92-
(idx int)
93-
(it {
94-
s: (string-ascii 39),
95-
r: uint,
96-
})
97-
)
98-
{
99-
s: (unwrap-panic (as-max-len?
100-
(concat (unwrap-panic (element-at? C32 (mod (get r it) u32))) (get s it))
101-
u39
102-
)),
103-
r: (/ (get r it) u32),
104-
}
105-
)
106-
107-
(define-read-only (hash-bytes-to-string (data (buff 24)))
108-
(let (
109-
(low-part (get s
110-
(fold c32-to-string-iter LIST_24 {
111-
s: "",
112-
r: (buff-to-uint-be (unwrap-panic (as-max-len? (unwrap-panic (slice? data u9 u24)) u16))),
113-
})
114-
))
115-
(high-part (get s
116-
(fold c32-to-string-iter LIST_15 {
117-
s: "",
118-
r: (buff-to-uint-be (unwrap-panic (as-max-len? (unwrap-panic (slice? data u0 u9)) u16))),
119-
})
120-
))
121-
)
122-
(unwrap-panic (as-max-len? (concat high-part low-part) u39))
123-
)
124-
)
125-
126-
(define-read-only (trim-leading-0-iter
127-
(idx int)
128-
(it (string-ascii 39))
129-
)
130-
(if (is-eq (element-at? it u0) (some "0"))
131-
(unwrap-panic (slice? it u1 (len it)))
132-
it
133-
)
134-
)
135-
136-
(define-read-only (trim-leading-0 (s (string-ascii 39)))
137-
(fold trim-leading-0-iter LIST_39 s)
138-
)
139-
140-
(define-read-only (append-leading-0-iter
141-
(idx int)
142-
(it {
143-
hash-bytes: (buff 24),
144-
address: (string-ascii 39),
145-
})
146-
)
147-
(if (is-eq (element-at? (get hash-bytes it) u0) (some 0x00))
148-
{
149-
hash-bytes: (unwrap-panic (slice? (get hash-bytes it) u1 (len (get hash-bytes it)))),
150-
address: (unwrap-panic (as-max-len? (concat "0" (get address it)) u39)),
151-
}
152-
it
153-
)
154-
)
155-
156-
(define-read-only (append-leading-0
157-
(hash-bytes (buff 24))
158-
(s (string-ascii 39))
159-
)
160-
(get address
161-
(fold append-leading-0-iter LIST_24 {
162-
hash-bytes: hash-bytes,
163-
address: s,
164-
})
165-
)
166-
)
167-
16859
;;;; Map getters
16960

170-
(define-read-only (relayer-to-stacks-get (universal-addr (buff 32)))
171-
(map-get? relayer-to-stacks universal-addr)
61+
(define-read-only (universal-address-to-principal-get (universal-addr (buff 32)))
62+
(map-get? universal-address-to-principal universal-addr)
17263
)

stacks/contracts/executor.clar

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
(define-constant ERR-QUOTE-SRC-CHAIN-MISMATCH (err u1001))
1818
(define-constant ERR-QUOTE-DST-CHAIN-MISMATCH (err u1002))
1919
(define-constant ERR-QUOTE-EXPIRED (err u1003))
20-
(define-constant ERR-UNREGISTERED-RELAYER (err u1004))
20+
(define-constant ERR-UNREGISTERED-PAYEE (err u1004))
2121
(define-constant ERR-INVALID-PAYEE-ADDRESS (err u1005))
2222
(define-constant ERR-BUFFER-PARSE-ERROR (err u1006))
2323
;;
@@ -50,25 +50,15 @@
5050
(asserts! (is-eq (len payee-universal-addr) u32)
5151
ERR-INVALID-PAYEE-ADDRESS
5252
)
53-
(asserts!
54-
(not (is-eq payee-universal-addr
55-
0x0000000000000000000000000000000000000000000000000000000000000000
56-
))
57-
ERR-INVALID-PAYEE-ADDRESS
58-
)
5953

60-
;; 2. Verify relayer is registered and get principal
61-
(let ((payee-lookup-result (contract-call? .executor-state relayer-to-stacks-get
54+
;; 2. Verify payee is registered and get principal
55+
(let ((payee-lookup-result (contract-call? .executor-state universal-address-to-principal-get
6256
payee-universal-addr
6357
)))
64-
(asserts! (is-some payee-lookup-result) ERR-UNREGISTERED-RELAYER)
58+
(asserts! (is-some payee-lookup-result) ERR-UNREGISTERED-PAYEE)
6559

66-
;; 3. Extract the principal and validate it's not contract address
60+
;; 3. Extract the principal for payment
6761
(let ((payee-principal (unwrap-panic payee-lookup-result)))
68-
(asserts! (not (is-eq payee-principal (as-contract tx-sender)))
69-
ERR-INVALID-PAYEE-ADDRESS
70-
)
71-
7262
;; 4. Perform the payment after all validations pass
7363
(try! (stx-transfer? payment tx-sender payee-principal))
7464

@@ -83,8 +73,6 @@
8373
signed-quote: signed-quote-bytes,
8474
request-bytes: request-bytes,
8575
relay-instructions: relay-instructions,
86-
block-height: stacks-block-height,
87-
tx-sender: tx-sender,
8876
})
8977

9078
(ok true)
@@ -166,10 +154,10 @@
166154
quote-dst-chain (match (extract-uint64-be signed-quote-bytes u60)
167155
expiry-time (if (is-eq quote-src-chain OUR-CHAIN)
168156
(if (is-eq quote-dst-chain dst-chain)
169-
;; Currently comparing Unix timestamp (expiry-time) with block height (stacks-block-height)
170-
;; Correct way is likely to do: (get-stacks-block-info? time stacks-block-height) which should return Unix timestamp
171-
;; Unable to write tests for it though as of now.
172-
(if (> expiry-time stacks-block-height)
157+
;; Compare Unix timestamp expiry-time with current block timestamp
158+
(if (> expiry-time
159+
(unwrap-panic (get-stacks-block-info? time stacks-block-height))
160+
)
173161
(ok true)
174162
ERR-QUOTE-EXPIRED
175163
)
@@ -203,9 +191,11 @@
203191
)
204192

205193
;; Convert 32-byte universal address hash back to a Stacks principal
206-
;; Uses the executor-state contract's relayer registry
194+
;; Uses the executor-state contract's payee registry
207195
(define-read-only (universal-addr-to-principal (universal-addr (buff 32)))
208-
(contract-call? .executor-state universal-addr-to-principal universal-addr)
196+
(contract-call? .executor-state universal-address-to-principal-get
197+
universal-addr
198+
)
209199
)
210200

211201
;; Read-only functions for external access

0 commit comments

Comments
 (0)