buildHandler adds the Core API routes to a preexisting http handler.
()
| 127 | |
| 128 | // buildHandler adds the Core API routes to a preexisting http handler. |
| 129 | func (a *API) buildHandler() { |
| 130 | needConfig := a.needConfig() |
| 131 | |
| 132 | resetAllowed := func(h http.Handler) http.Handler { return alwaysError(errNoReset) } |
| 133 | if config.BuildConfig.Reset { |
| 134 | resetAllowed = func(h http.Handler) http.Handler { return h } |
| 135 | } |
| 136 | |
| 137 | m := a.mux |
| 138 | m.Handle("/", alwaysError(errNotFound)) |
| 139 | |
| 140 | m.Handle("/create-account", needConfig(a.createAccount)) |
| 141 | m.Handle("/create-asset", needConfig(a.createAsset)) |
| 142 | m.Handle("/update-account-tags", needConfig(a.updateAccountTags)) |
| 143 | m.Handle("/update-asset-tags", needConfig(a.updateAssetTags)) |
| 144 | m.Handle("/build-transaction", needConfig(a.build)) |
| 145 | m.Handle("/submit-transaction", needConfig(a.submit)) |
| 146 | m.Handle("/create-control-program", needConfig(a.createControlProgram)) // DEPRECATED |
| 147 | m.Handle("/create-account-receiver", needConfig(a.createAccountReceiver)) |
| 148 | m.Handle("/create-transaction-feed", needConfig(a.createTxFeed)) |
| 149 | m.Handle("/get-transaction-feed", needConfig(a.getTxFeed)) |
| 150 | m.Handle("/update-transaction-feed", needConfig(a.updateTxFeed)) |
| 151 | m.Handle("/delete-transaction-feed", needConfig(a.deleteTxFeed)) |
| 152 | m.Handle("/mockhsm", alwaysError(errNoMockHSM)) |
| 153 | m.Handle("/list-accounts", needConfig(a.listAccounts)) |
| 154 | m.Handle("/list-assets", needConfig(a.listAssets)) |
| 155 | m.Handle("/list-transaction-feeds", needConfig(a.listTxFeeds)) |
| 156 | m.Handle("/list-transactions", needConfig(a.listTransactions)) |
| 157 | m.Handle("/list-balances", needConfig(a.listBalances)) |
| 158 | m.Handle("/list-unspent-outputs", needConfig(a.listUnspentOutputs)) |
| 159 | m.Handle("/reset", resetAllowed(needConfig(a.reset))) |
| 160 | |
| 161 | m.Handle(crosscoreRPCPrefix+"submit", needConfig(func(ctx context.Context, tx *legacy.Tx) error { |
| 162 | return a.submitter.Submit(ctx, tx) |
| 163 | })) |
| 164 | m.Handle(crosscoreRPCPrefix+"get-block", needConfig(a.getBlockRPC)) |
| 165 | m.Handle(crosscoreRPCPrefix+"get-snapshot-info", needConfig(a.getSnapshotInfoRPC)) |
| 166 | m.Handle(crosscoreRPCPrefix+"get-snapshot", http.HandlerFunc(a.getSnapshotRPC)) |
| 167 | m.Handle(crosscoreRPCPrefix+"signer/sign-block", needConfig(a.leaderSignHandler(a.signer))) |
| 168 | m.Handle(crosscoreRPCPrefix+"block-height", needConfig(func(ctx context.Context) map[string]uint64 { |
| 169 | h := a.chain.Height() |
| 170 | return map[string]uint64{ |
| 171 | "block_height": h, |
| 172 | } |
| 173 | })) |
| 174 | |
| 175 | m.Handle("/list-authorization-grants", jsonHandler(a.listGrants)) |
| 176 | m.Handle("/create-authorization-grant", jsonHandler(a.createGrant)) |
| 177 | m.Handle("/delete-authorization-grant", jsonHandler(a.deleteGrant)) |
| 178 | m.Handle("/create-access-token", jsonHandler(a.createAccessToken)) |
| 179 | m.Handle("/list-access-tokens", jsonHandler(a.listAccessTokens)) |
| 180 | m.Handle("/delete-access-token", jsonHandler(a.deleteAccessToken)) |
| 181 | m.Handle("/add-allowed-member", jsonHandler(a.addAllowedMember)) |
| 182 | m.Handle("/configure", jsonHandler(a.configure)) |
| 183 | m.Handle("/info", jsonHandler(a.info)) |
| 184 | |
| 185 | m.Handle("/debug/vars", expvar.Handler()) |
| 186 | m.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index)) |