return accounts, nil
}
+
+// ListControlProgram return all the local control program
+func (m *Manager) ListControlProgram() ([]*CtrlProgram, error) {
+ cps := []*CtrlProgram{}
+ cpIter := m.db.IteratorPrefix([]byte(accountCPPrefix))
+ defer cpIter.Release()
+
+ for cpIter.Next() {
+ cp := &CtrlProgram{}
+ if err := json.Unmarshal(cpIter.Value(), cp); err != nil {
+ return nil, err
+ }
+ cps = append(cps, cp)
+ }
+
+ return cps, nil
+}
resp.IsLocal = bcr.accounts.IsLocalControlProgram(program)
return NewSuccessResponse(resp)
}
+
+type addressResp struct {
+ AccountID string `json:"account_id"`
+ Address string `json:"address"`
+}
+
+func (bcr *BlockchainReactor) listAddresses(ctx context.Context) Response {
+ cps, err := bcr.accounts.ListControlProgram()
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+
+ addresses := []*addressResp{}
+ for _, cp := range cps {
+ if cp.Address == "" {
+ continue
+ }
+ addresses = append(addresses, &addressResp{AccountID: cp.AccountID, Address: cp.Address})
+ }
+ return NewSuccessResponse(addresses)
+}
m.Handle("/update-account-tags", jsonHandler(bcr.updateAccountTags))
m.Handle("/create-account-receiver", jsonHandler(bcr.createAccountReceiver))
m.Handle("/list-accounts", jsonHandler(bcr.listAccounts))
+ m.Handle("/list-addresses", jsonHandler(bcr.listAddresses))
m.Handle("/delete-account", jsonHandler(bcr.deleteAccount))
m.Handle("/validate-address", jsonHandler(bcr.validateAddress))