This repository has been archived by the owner on Nov 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
rescue.go
154 lines (144 loc) · 5.57 KB
/
rescue.go
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
package main
import (
"fmt"
"log"
"strings"
scan "github.com/Varunram/essentials/scan"
xlm "github.com/Varunram/essentials/xlm"
assets "github.com/Varunram/essentials/xlm/assets"
multisig "github.com/Varunram/essentials/xlm/multisig"
consts "github.com/YaleOpenLab/openx/consts"
)
// rescue mode contains a list of handlers that can be used when we need to login as any account and perform emergency resuce fns
// call this after starting the platform so we don't have to do the boring stuff again if we're the platform
// this will no have any sort of input parsing since only admins will be using it in the event of an emergency
// RescueMode starts openx in rescue mode as the platform in order to be able to salvage funds
// in case of a hack / disruption.
func RescueMode() {
seed := consts.PlatformSeed
pubkey := consts.PlatformPublicKey
fmt.Println(`
██████╗ ███████╗███████╗ ██████╗██╗ ██╗███████╗ ███╗ ███╗ ██████╗ ██████╗ ███████╗
██╔══██╗██╔════╝██╔════╝██╔════╝██║ ██║██╔════╝ ████╗ ████║██╔═══██╗██╔══██╗██╔════╝
██████╔╝█████╗ ███████╗██║ ██║ ██║█████╗ ██╔████╔██║██║ ██║██║ ██║█████╗
██╔══██╗██╔══╝ ╚════██║██║ ██║ ██║██╔══╝ ██║╚██╔╝██║██║ ██║██║ ██║██╔══╝
██║ ██║███████╗███████║╚██████╗╚██████╔╝███████╗ ██║ ╚═╝ ██║╚██████╔╝██████╔╝███████╗
╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚══════╝
`)
for {
log.Println("WELCOME TO RESCUE MODE")
log.Println("LIST OF FUNCTIONS AVAILABLE")
log.Println("1. Send funds to another address")
log.Println("2. Sweep funds from platform")
log.Println("3. View platform balances")
log.Println("4. Sweep XLM from project escrow")
log.Println("5. Send USD to another address")
choice, err := scan.Int()
if err != nil {
log.Fatal(err)
}
switch choice {
case 1:
log.Println("Enter address")
address, err := scan.String()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
log.Println("Enter amount")
amount, err := scan.Float()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
log.Println("address: ", address, "amount: ", amount)
if !xlm.AccountExists(address) {
_, _, err = xlm.SendXLMCreateAccount(address, amount, seed)
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
} else {
_, _, err = xlm.SendXLM(address, amount, seed, "rescue mode")
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
}
case 2:
log.Println("Enter sweep address")
address, err := scan.String()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
amount := xlm.GetNativeBalance(pubkey)
log.Println("SWEEP AMOUNT IS: ", amount)
// send the tx over
_, _, err = xlm.SendXLM(address, amount-5, seed, "rescue mode sweep")
if err != nil {
log.Println("error while transferring funds to secondary account, quitting")
break
}
case 3:
balances, err := xlm.GetAllBalances(pubkey)
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
continue
}
log.Println(balances)
case 4:
log.Println("Enter escrow address")
source, err := scan.String()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
amount := xlm.GetNativeBalance(source)
log.Println("Enter sweep address")
destination, err := scan.String()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
log.Println("Enter other signer's seed")
otherSeed, err := scan.String()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
err = multisig.Tx2of2(source, destination, otherSeed, seed, amount, "escrow sweep")
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
case 5:
log.Println("Trustline must already exiust for specified seed")
log.Println("Enter address")
address, err := scan.String()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
log.Println("Enter amount")
amount, err := scan.Float()
if err != nil {
log.Println("!!!" + strings.ToUpper(err.Error()) + "!!!")
break
}
log.Println("AMOUNT IS: ", amount)
balance := xlm.GetAssetBalance(pubkey, consts.AnchorUSDCode)
log.Println("Available balance: ", balance)
if balance < amount {
log.Println("insufficient balance")
break
}
_, _, err = assets.SendAsset(consts.AnchorUSDCode, consts.AnchorUSDAddress, address, amount,
seed, "tf")
if err != nil {
log.Println(err)
break
}
}
}
}