Add getAccountUtxo method to websocket interface

This commit is contained in:
Martin Boehm 2019-01-14 17:12:33 +01:00
parent 05daf85c10
commit 1c29283bf0
3 changed files with 43 additions and 1 deletions

View File

@ -765,6 +765,9 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, option GetA
// GetAddressUtxo returns unspent outputs for given address
func (w *Worker) GetAddressUtxo(address string, onlyConfirmed bool) ([]AddressUtxo, error) {
if w.chainType != bchain.ChainBitcoinType {
return nil, NewAPIError("Not supported", true)
}
start := time.Now()
addrDesc, err := w.chainParser.GetAddrDescFromAddress(address)
if err != nil {

View File

@ -237,6 +237,16 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *webs
}
return
},
"getAccountUtxo": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) {
r := struct {
Descriptor string `json:"descriptor"`
}{}
err = json.Unmarshal(req.Params, &r)
if err == nil {
rv, err = s.getAccountUtxo(r.Descriptor)
}
return
},
"estimateFee": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) {
return s.estimateFee(c, req.Params)
},
@ -338,7 +348,6 @@ func (s *WebsocketServer) getAccountInfo(req *accountInfoReq) (res *api.Address,
default:
opt = api.Basic
}
return s.api.GetAddress(req.Descriptor, req.Page, req.PageSize, opt, &api.AddressFilter{
FromHeight: uint32(req.FromHeight),
ToHeight: uint32(req.ToHeight),
@ -347,6 +356,10 @@ func (s *WebsocketServer) getAccountInfo(req *accountInfoReq) (res *api.Address,
})
}
func (s *WebsocketServer) getAccountUtxo(descriptor string) (interface{}, error) {
return s.api.GetAddressUtxo(descriptor, false)
}
func (s *WebsocketServer) getInfo() (interface{}, error) {
vi := common.GetVersionInfo()
height, hash, err := s.db.GetBestBlock()

View File

@ -141,6 +141,17 @@
});
}
function getAccountUtxo() {
const descriptor = document.getElementById('getAccountUtxoDescriptor').value.trim();
const method = 'getAccountUtxo';
const params = {
descriptor,
};
send(method, params, function (result) {
document.getElementById('getAccountUtxoResult').innerText = JSON.stringify(result).replace(/,/g, ", ");
});
}
function estimateFee() {
try {
var blocks = document.getElementById('estimateFeeBlocks').value.split(",");
@ -302,6 +313,21 @@
<div class="col" id="getAccountInfoResult">
</div>
</div>
<div class="row">
<div class="col">
<input class="btn btn-secondary" type="button" value="getAccountUtxo" onclick="getAccountUtxo()">
</div>
<div class="col-8">
<div class="row" style="margin: 0;">
<input type="text" placeholder="descriptor" style="width: 79%" class="form-control" id="getAccountUtxoDescriptor" value="0xba98d6a5ac827632e3457de7512d211e4ff7e8bd">
</div>
</div>
<div class="col form-inline"></div>
</div>
<div class="row">
<div class="col" id="getAccountUtxoResult">
</div>
</div>
<div class="row">
<div class="col">
<input class="btn btn-secondary" type="button" value="estimateFee" onclick="estimateFee()">