Repository navigation
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·106 lines (89 loc) · 3.09 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·106 lines (89 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env bash
# Minimal end-to-end example using the Stellar CLI:
# deploys token, mints to buyer, runs full escrow lifecycle against a local node.
#
# Prerequisites:
# stellar-cli installed (cargo install --locked stellar-cli --features opt)
# ./scripts/local-net.sh start
#
# Usage:
# ./examples/shell/run.sh
set -euo pipefail
NETWORK="${STELLAR_NETWORK:-local}"
RPC_URL="${SOROBAN_RPC_URL:-http://localhost:8000/soroban/rpc}"
NETWORK_PASSPHRASE="${NETWORK_PASSPHRASE:-Standalone Network ; February 2017}"
MINT_AMOUNT=1000000
ESCROW_AMOUNT=500000
DEADLINE=$(( $(date +%s) + 3600 ))
echo "=== Generating keypairs ==="
stellar keys generate admin --network "$NETWORK" --overwrite
stellar keys generate buyer --network "$NETWORK" --overwrite
stellar keys generate seller --network "$NETWORK" --overwrite
ADMIN_KEY=$(stellar keys address admin)
BUYER_KEY=$(stellar keys address buyer)
SELLER_KEY=$(stellar keys address seller)
echo "Admin: $ADMIN_KEY"
echo "Buyer: $BUYER_KEY"
echo "Seller: $SELLER_KEY"
echo ""
echo "=== Funding accounts via friendbot ==="
curl -sf "http://localhost:8000/friendbot?addr=$ADMIN_KEY" > /dev/null
curl -sf "http://localhost:8000/friendbot?addr=$BUYER_KEY" > /dev/null
curl -sf "http://localhost:8000/friendbot?addr=$SELLER_KEY" > /dev/null
echo "Funded all accounts"
echo ""
echo "=== Building and deploying contracts ==="
stellar contract build --manifest-path contracts/token/Cargo.toml 2>/dev/null
stellar contract build --manifest-path contracts/escrow/Cargo.toml 2>/dev/null
TOKEN_ID=$(stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/token.wasm \
--source admin \
--network "$NETWORK")
ESCROW_ID=$(stellar contract deploy \
--wasm target/wasm32-unknown-unknown/release/escrow.wasm \
--source admin \
--network "$NETWORK")
echo "Token contract: $TOKEN_ID"
echo "Escrow contract: $ESCROW_ID"
echo ""
echo "=== Initializing token contract ==="
stellar contract invoke --id "$TOKEN_ID" --source admin --network "$NETWORK" \
-- initialize \
--admin "$ADMIN_KEY" \
--name "DemoToken" \
--symbol "DEMO" \
--decimal 7
echo ""
echo "=== Minting tokens to buyer ==="
stellar contract invoke --id "$TOKEN_ID" --source admin --network "$NETWORK" \
-- mint \
--to "$BUYER_KEY" \
--amount "$MINT_AMOUNT"
echo "Minted $MINT_AMOUNT DEMO to buyer"
echo ""
echo "=== Creating escrow ==="
stellar contract invoke --id "$ESCROW_ID" --source buyer --network "$NETWORK" \
-- create \
--buyer "$BUYER_KEY" \
--seller "$SELLER_KEY" \
--token "$TOKEN_ID" \
--amount "$ESCROW_AMOUNT" \
--deadline "$DEADLINE"
echo "Escrow created"
echo ""
echo "=== Funding escrow ==="
stellar contract invoke --id "$ESCROW_ID" --source buyer --network "$NETWORK" \
-- fund
echo "Escrow funded"
echo ""
echo "=== Marking delivery ==="
stellar contract invoke --id "$ESCROW_ID" --source seller --network "$NETWORK" \
-- mark_delivery
echo "Delivery marked"
echo ""
echo "=== Releasing funds to seller ==="
stellar contract invoke --id "$ESCROW_ID" --source buyer --network "$NETWORK" \
-- release
echo "Funds released"
echo ""
echo "Full escrow lifecycle complete."