/
walletapi.go
207 lines (166 loc) · 8.28 KB
/
walletapi.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"time"
"github.com/FactomProject/FactomCode/util"
fct "github.com/FactomProject/factoid"
"github.com/FactomProject/factom"
"github.com/FactomProject/fctwallet/handlers"
"github.com/FactomProject/web"
)
var _ = fct.Address{}
var server = web.NewServer()
func Start() {
// Balance
// localhost:8089/v1/factoid-balance/<name or address>
// Returns the balance of factoids at that address, or the address tied to
// the given name.
server.Get("/v1/factoid-balance/([^/]+)", handlers.HandleFactoidBalance)
// Balance
// localhost:8089/v1/factoid-balance/<name or address>
// Returns the balance of entry credits at that address, or the address tied to
// the given name.
server.Get("/v1/entry-credit-balance/([^/]+)", handlers.HandleEntryCreditBalance)
// Generate Address
// localhost:8089/v1/factoid-generate-address/<name>
// Generate an address, and tie it to the given name within the wallet. You
// can use the name for the address in this API
server.Get("/v1/factoid-generate-address/([^/]+)", handlers.HandleFactoidGenerateAddress)
// Generate Entry Credit Address
// localhost:8089/v1/factoid-generate-ec-address/<name>
// Generate an address, and tie it to the given name within the wallet. You
// can use the name for the address in this API
server.Get("/v1/factoid-generate-ec-address/([^/]+)", handlers.HandleFactoidGenerateECAddress)
server.Get("/v1/factoid-generate-address-from-private-key/(.*)", handlers.HandleFactoidGenerateAddressFromPrivateKey)
server.Get("/v1/factoid-generate-ec-address-from-private-key/(.*)", handlers.HandleFactoidGenerateECAddressFromPrivateKey)
server.Get("/v1/factoid-generate-address-from-human-readable-private-key/(.*)", handlers.HandleFactoidGenerateAddressFromHumanReadablePrivateKey)
server.Get("/v1/factoid-generate-ec-address-from-human-readable-private-key/(.*)", handlers.HandleFactoidGenerateECAddressFromHumanReadablePrivateKey)
server.Get("/v1/factoid-generate-address-from-token-sale/(.*)", handlers.HandleFactoidGenerateAddressFromMnemonic)
// resolve-address does a DNS lookup of an address on netki and returns a
// human readable factoid and/or entry credit address
server.Get("/v1/resolve-address/(.*)", handlers.HandleResolveAddress)
// verify-address-type
// localhost:8089/v1/verify-address-type/address=<address>
// take address and define its type or fail if not valid address
// returns Success true r false in json with type if true
server.Get("/v1/verify-address-type/(.*)", handlers.HandleVerifyAddressType)
// Compose Chain
// localhost:8089/v1/compose-chain-submit/<name or address
// Returns a json object to be used for the commit and reveal api calls
// to factomd.
server.Post("/v1/compose-chain-submit/([^/]+)", handlers.HandleComposeChainSubmit)
// Compose Entry
// localhost:8089/v1/compose-entry-submit/<name or address
// Returns a json object to be used for the commit and reveal api calls
// to factomd.
server.Post("/v1/compose-entry-submit/([^/]+)", handlers.HandleComposeEntrySubmit)
// New Transaction
// localhost:8089/v1/factoid-new-transaction/<key>
// Use the key in subsequent calls to add inputs, outputs, ecoutputs, and to
// sign and submit the transaction. Returns Success == true if all is well.
// Multiple transactions can be in process. Only one transaction per key.
// Once the transaction has been submitted or deleted, the key can be
// reused.
server.Post("/v1/factoid-new-transaction/([^/]+)", handlers.HandleFactoidNewTransaction)
// Delete Transaction
// localhost:8089/v1/factoid-new-transaction/<key>
// Remove the key of a transaction in flight. If it doesn't exist, then
// nobody cares.
server.Post("/v1/factoid-delete-transaction/([^/]+)", handlers.HandleFactoidDeleteTransaction)
// Add Fee
// localhost:8089/v1/factoid-add-fee/?key=<key>&name=<name or address>
// Add the fee for this transaction to the input specified by the name or
// address.
// If the name or address is not an input to this transaction, then an error
// is posted.
server.Post("/v1/factoid-add-fee/(.*)", handlers.HandleFactoidAddFee)
// Sub Fee
// localhost:8089/v1/factoid-sub-fee/?key=<key>&name=<name or address>
// Subtract the fee for this transaction to the input specified by the name
// or address.
// If the name or address is not an input to this transaction, then an error
// is posted.
server.Post("/v1/factoid-sub-fee/(.*)", handlers.HandleFactoidSubFee)
// Add Input
// localhost:8089/v1/factoid-add-input/?key=<key>&name=<name or address>&amount=<amount>
// Add an input to a transaction in process. Start with new-transaction.
server.Post("/v1/factoid-add-input/(.*)", handlers.HandleFactoidAddInput)
// Add Output
// localhost:8089/v1/factoid-add-output/?key=<key>&name=<name or address>&amount=<amount>
// Add an output to a transaction in process. Start with new-transaction.
server.Post("/v1/factoid-add-output/(.*)", handlers.HandleFactoidAddOutput)
// Add Entry Credit Output
// localhost:8089/v1/factoid-add-ecoutput/?key=<key>&name=<name or address>&amount=<amount>
// Add an ecoutput to a transaction in process. Start with new-transaction.
server.Post("/v1/factoid-add-ecoutput/(.*)", handlers.HandleFactoidAddECOutput)
// Sign Transaction
// localhost:8089/v1/factoid-sign-transaction/<key>
// If the transaction validates structure wise and all signatures can be
// applied, then all inputs are signed, and returns success = true
// Otherwise returns false. Note that this doesn't check that the inputs
// can cover the transaction. Use validate to do that.
server.Post("/v1/factoid-sign-transaction/(.*)", handlers.HandleFactoidSignTransaction)
// Setup
// localhost:8089/v1/factoid-setup/<key>
// hashes the given data to create a new seed from which to generate addresses.
// The point is to create unique and secure addresses for this user.
// removed the API to create a new seed in a wallet.
// server.Post("/v1/factoid-setup/(.*)", handlers.HandleFactoidSetup)
// Commit Chain
// localhost:8089/v1/commit-chain/
// sign a binary Chain Commit with an entry credit key and submit it to the
// factomd server
server.Post("/v1/commit-chain/([^/]+)", handlers.HandleCommitChain)
// Commit Entry
// localhost:8089/v1/commit-entry/
// sign a binary Entry Commit with an entry credit key and submit it to the
// factomd server
server.Post("/v1/commit-entry/([^/]+)", handlers.HandleCommitEntry)
// Submit
// localhost:8089/v1/factoid-submit/
// Put the key for the transaction in {Transaction string}
server.Post("/v1/factoid-submit/(.*)", handlers.HandleFactoidSubmit)
// Validate
// localhost:8089/v1/factoid-validate/<key>
// Validates amounts and that all required signatures are applied, returns success = true
// Otherwise returns false.
server.Get("/v1/factoid-validate/(.*)", handlers.HandleFactoidValidate)
// Get Fee
// localhost:8089/v1/factoid-get-fee/
// Get the Transaction fee
server.Get("/v1/factoid-get-fee/(.*)", handlers.HandleGetFee)
// Get Fee
// localhost:8089/v1/factoid-get-fee/
// Get the Transaction fee
server.Get("/v1/properties/", handlers.HandleProperties)
// Get Address List
// localhost:8089/v1/factoid-get-addresses/
server.Get("/v1/factoid-get-addresses/", handlers.HandleGetAddresses)
// Get transactions
// localhost:8089/v1/factoid-get-addresses/
server.Get("/v1/factoid-get-transactions/", handlers.HandleGetTransactions)
// Get transactions
// localhost:8089/v1/factoid-get-addresses/
server.Get("/v1/factoid-get-transactionsj/", handlers.HandleGetTransactionsj)
// Get processed transactions
// localhost:8089/v1/factoid-get-addresses/
server.Post("/v1/factoid-get-processed-transactions/(.*)", handlers.HandleGetProcessedTransactions)
// Get processed transactions
// localhost:8089/v1/factoid-get-addresses/
server.Post("/v1/factoid-get-processed-transactionsj/(.*)", handlers.HandleGetProcessedTransactionsj)
go server.Run(fmt.Sprintf("%s:%d", handlers.IpAddress, handlers.PortNumber))
}
func main() {
fmt.Println("+================+")
fmt.Println("| fctwallet v1 |")
fmt.Println("+================+")
cfg := util.ReadConfig().Wallet
factom.SetServer(fmt.Sprintf("%s:%d", cfg.FactomdAddress, cfg.FactomdPort))
Start()
for {
time.Sleep(time.Second)
}
}