forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·178 lines (151 loc) · 5.47 KB
/
Copy pathdeploy.sh
File metadata and controls
executable file
·178 lines (151 loc) · 5.47 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env bash
#
# Deploy the Invoisio invoice-payment contract to Stellar
#
# Usage:
# ./deploy.sh # deploys to testnet (default)
# STELLAR_NETWORK=mainnet ./deploy.sh # deploys to mainnet
#
# Environment variables:
# STELLAR_NETWORK - Network to deploy to (default: testnet)
# STELLAR_IDENTITY - Override identity name from manifest
# INVOISIO_ADMIN_SECRET - Admin secret key (optional; falls back to local keys identity)
#
# Manifest files (read automatically based on STELLAR_NETWORK):
# manifests/testnet.toml
# manifests/mainnet.toml
#
# The script will:
# 1. Load the network manifest for the target environment
# 2. Create/verify the identity exists
# 3. Fund the account from Friendbot (testnet only)
# 4. Deploy the contract WASM
# 5. Initialize the contract with the admin address
# 6. Save the CONTRACT_ID to the path defined in the manifest
set -e
cd "$(dirname "$0")"
# ── Load manifest ────────────────────────────────────────────────────────────
NETWORK="${STELLAR_NETWORK:-testnet}"
MANIFEST_FILE="manifests/${NETWORK}.toml"
if [ ! -f "$MANIFEST_FILE" ]; then
echo "❌ Error: No manifest found for network '${NETWORK}'"
echo " Expected: ${MANIFEST_FILE}"
echo " Available manifests: $(ls manifests/*.toml 2>/dev/null | xargs -n1 basename | tr '\n' ' ')"
exit 1
fi
echo "📋 Loading manifest: ${MANIFEST_FILE}"
# Parse TOML values with grep (no external deps required)
_toml_get() {
grep -E "^${1}\s*=" "$MANIFEST_FILE" | head -1 | sed 's/^[^=]*=\s*//' | tr -d '"' | tr -d "'"
}
MANIFEST_IDENTITY="$(_toml_get identity.name 2>/dev/null || true)"
MANIFEST_WASM_PATH="$(_toml_get wasm_path 2>/dev/null || true)"
MANIFEST_CONTRACT_ID_FILE="$(_toml_get contract_id_file 2>/dev/null || true)"
MANIFEST_SECRET_KEY_ENV="$(_toml_get secret_key_env 2>/dev/null || true)"
# Resolve configuration (env overrides manifest)
IDENTITY="${STELLAR_IDENTITY:-${MANIFEST_IDENTITY:-invoisio-admin}}"
WASM_PATH="${MANIFEST_WASM_PATH:-target/wasm32v1-none/release/invoice_payment.wasm}"
CONTRACT_ID_FILE="${MANIFEST_CONTRACT_ID_FILE:-contracts/invoice-payment/.contract-id}"
# If a secret key env var is configured in the manifest, try to use it
if [ -n "$MANIFEST_SECRET_KEY_ENV" ]; then
ADMIN_SECRET="${!MANIFEST_SECRET_KEY_ENV:-}"
fi
echo "========================================="
echo "Deploying Invoisio Contract"
echo "========================================="
echo ""
echo "Network: $NETWORK"
echo "Identity: $IDENTITY"
echo ""
# Check prerequisites
if ! command -v stellar &> /dev/null; then
echo "❌ Error: stellar CLI not found"
echo "Run ./build.sh first to check prerequisites"
exit 1
fi
# Check WASM exists
if [ ! -f "$WASM_PATH" ]; then
echo "❌ Error: Contract WASM not found at $WASM_PATH"
echo ""
echo "Build the contract first:"
echo " ./build.sh"
exit 1
fi
# Step 1: Create or verify identity
echo "🔑 Step 1/4: Setting up identity '$IDENTITY'..."
echo ""
if stellar keys show "$IDENTITY" &> /dev/null; then
echo "✅ Identity '$IDENTITY' already exists"
ADMIN_ADDRESS=$(stellar keys address "$IDENTITY")
echo " Address: $ADMIN_ADDRESS"
else
echo "📝 Creating new identity '$IDENTITY'..."
stellar keys generate --global "$IDENTITY" --network "$NETWORK"
ADMIN_ADDRESS=$(stellar keys address "$IDENTITY")
echo "✅ Identity created"
echo " Address: $ADMIN_ADDRESS"
fi
echo ""
# Step 2: Fund account (testnet only)
if [ "$NETWORK" = "testnet" ]; then
echo "💰 Step 2/4: Funding account from Friendbot..."
echo ""
if stellar keys fund "$IDENTITY" --network "$NETWORK" 2>&1; then
echo "✅ Account funded successfully"
else
echo "⚠️ Funding may have failed (account might already have balance)"
echo " Continuing with deployment..."
fi
else
echo "⚠️ Step 2/4: Skipping Friendbot funding (not on testnet)"
echo " Ensure the account has sufficient XLM balance"
fi
echo ""
# Step 3: Deploy contract
echo "🚀 Step 3/4: Deploying contract to $NETWORK..."
echo ""
CONTRACT_ID=$(stellar contract deploy \
--wasm "$WASM_PATH" \
--source "$IDENTITY" \
--network "$NETWORK")
echo "✅ Contract deployed!"
echo " Contract ID: $CONTRACT_ID"
echo ""
# Save contract ID with secure permissions
echo "$CONTRACT_ID" > "$CONTRACT_ID_FILE"
chmod 600 "$CONTRACT_ID_FILE" 2>/dev/null || true # Secure file, ignore on Windows
echo "💾 Contract ID saved to $CONTRACT_ID_FILE"
echo ""
# Step 4: Initialize contract
echo "⚙️ Step 4/4: Initializing contract..."
echo ""
stellar contract invoke \
--id "$CONTRACT_ID" \
--source "$IDENTITY" \
--network "$NETWORK" \
-- initialize \
--admin "$ADMIN_ADDRESS"
echo ""
echo "✅ Contract initialized with admin: $ADMIN_ADDRESS"
echo ""
# Success summary
echo "========================================="
echo "🎉 Deployment Complete!"
echo "========================================="
echo ""
echo "Contract ID: $CONTRACT_ID"
echo "Admin: $ADMIN_ADDRESS"
echo "Network: $NETWORK"
echo ""
echo "Next steps:"
echo ""
echo " Record a payment (XLM):"
echo " ./invoke-record-payment.sh \\"
echo " invoisio-demo-001 \\"
echo " $ADMIN_ADDRESS \\"
echo " XLM \"\" 10000000 \\"
echo " settle-demo-001"
echo ""
echo " Query a payment:"
echo " ./invoke-get-payment.sh invoisio-demo-001"
echo ""