Skip to content

Commit

Permalink
util contract not found
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusVorwald committed May 23, 2024
1 parent 95f67a3 commit ca75c11
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 34 deletions.
102 changes: 68 additions & 34 deletions contracts/xcall/call-service.clar
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

(define-public (handle-message (from (string-ascii 150)) (sequence uint) (data (buff 1024)))
(let ((chain-identifier (unwrap-panic (get-chain-identifier from))))
(let ((contract-address (unwrap-panic (contract-call? .util address-string-to-principal from))))
(let ((contract-address (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? from 128))))))
(let ((current-sequence (unwrap-panic (get-current-sequence chain-identifier contract-address))))
(asserts! (is-eq sequence (+ current-sequence u1)) ERR_INVALID_SEQUENCE)
(unwrap-panic (increment-sequence chain-identifier contract-address))
Expand Down Expand Up @@ -86,39 +86,73 @@
)
)

(define-private (handle-call-message (from (string-ascii 150)) (data (buff 1024)))
(let ((decoded-data (contract-call? .rlp-decode rlp-to-list data)))
(let ((target-contract (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? (contract-call? .rlp-decode rlp-decode-string decoded-data u0) u128))))))
(let ((function-name (contract-call? .rlp-decode rlp-decode-string decoded-data u1)))
(let ((args (contract-call? .rlp-decode rlp-decode-list decoded-data u2)))
(if (is-eq function-name "execute")
(let ((amount (contract-call? .rlp-decode rlp-decode-uint args u0)))
(let ((token (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? (contract-call? .rlp-decode rlp-decode-string args u1) u128))))))
(let ((sender (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? from u128))))))
(if (is-eq contract-caller tx-sender)
(begin
(try! (as-contract (contract-call? token transfer amount tx-sender sender none)))
(print "execute-success" { from: from, target-contract: target-contract })
(ok true)
)
(begin
(print "unauthorized-caller" { caller: contract-caller })
ERR_UNAUTHORIZED
)
)
)
)
)
(begin
(print "unsupported-function" { function-name: function-name })
ERR_UNSUPPORTED_FUNCTION
)
)
)
)
)
)
)
;; (define-private (handle-call-message (from (string-ascii 150)) (data (buff 1024)))
;; (let ((decoded-data (contract-call? .rlp-decode rlp-to-list data)))
;; (let ((target-contract (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? (contract-call? .rlp-decode rlp-decode-string decoded-data u0) u128))))))
;; (let ((function-name (contract-call? .rlp-decode rlp-decode-string decoded-data u1)))
;; (let ((args (contract-call? .rlp-decode rlp-decode-list decoded-data u2)))
;; (if (is-eq function-name "execute")
;; (let ((amount (contract-call? .rlp-decode rlp-decode-uint args u0)))
;; (let ((token (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? (contract-call? .rlp-decode rlp-decode-string args u1) u128))))))
;; (let ((sender (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? from u128))))))
;; (if (is-eq contract-caller tx-sender)
;; (begin
;; (try! (as-contract (contract-call? token transfer amount tx-sender sender none)))
;; (print "execute-success" { from: from, target-contract: target-contract })
;; (ok true)
;; )
;; (begin
;; (print "unauthorized-caller" { caller: contract-caller })
;; ERR_UNAUTHORIZED
;; )
;; )
;; )
;; )
;; )
;; (begin
;; (print "unsupported-function" { function-name: function-name })
;; ERR_UNSUPPORTED_FUNCTION
;; )
;; )
;; )
;; )
;; )
;; )
;; )

;; (define-private (handle-call-message (from (string-ascii 150)) (data (buff 1024)))
;; (let ((decoded-data (contract-call? .rlp-decode rlp-to-list data)))
;; (let ((target-contract (contract-call? .rlp-decode rlp-decode-string decoded-data u0)))
;; (let ((function-name (contract-call? .rlp-decode rlp-decode-string decoded-data u1)))
;; (let ((args (contract-call? .rlp-decode rlp-decode-list decoded-data u2)))
;; (if (and (is-eq target-contract "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.contract-goes-here") (is-eq function-name "transfer"))
;; (let ((amount (contract-call? .rlp-decode rlp-decode-uint args u0)))
;; (let ((recipient (unwrap-panic (contract-call? .util address-string-to-principal (unwrap-panic (as-max-len? (contract-call? .rlp-decode rlp-decode-string args u1) 128))))))
;; (let ((sender (unwrap-panic (contract-call? .util address-string-to-principal from))))
;; (if (is-eq contract-caller tx-sender)
;; (begin
;; (try! (as-contract (contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.contract-goes-here transfer amount tx-sender recipient none)))
;; (print "transfer-success" { from: from, recipient: recipient, amount: amount })
;; (ok true)
;; )
;; (begin
;; (print "unauthorized-caller" { caller: contract-caller })
;; ERR_UNAUTHORIZED
;; )
;; )
;; )
;; )
;; )
;; (begin
;; (print "unsupported-function" { target-contract: target-contract, function-name: function-name })
;; ERR_UNSUPPORTED_FUNCTION
;; )
;; )
;; )
;; )
;; )
;; )
;; )

;; Execute a cross-chain message
(define-public (execute-message (chain-identifier (string-ascii 50)) (sequence uint) (data (buff 1024)))
Expand Down
10 changes: 10 additions & 0 deletions deployments/default.simnet-plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ plan:
batches:
- id: 0
transactions:
- emulated-contract-publish:
contract-name: util
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/util.clar
clarity-version: 2
- emulated-contract-publish:
contract-name: call-service
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
Expand All @@ -74,4 +79,9 @@ plan:
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: contracts/xcall/fee-manage-trait.clar
clarity-version: 2
- emulated-contract-publish:
contract-name: rlp-decode
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
path: lib/rlp/rlp-decode.clar
clarity-version: 2
epoch: "2.4"

0 comments on commit ca75c11

Please sign in to comment.