Add websocket method getTransaction

This commit is contained in:
Martin Boehm 2019-01-16 16:10:30 +01:00
parent 3a8e854384
commit 9af314f7aa
2 changed files with 42 additions and 2 deletions

View File

@ -247,6 +247,16 @@ var requestHandlers = map[string]func(*WebsocketServer, *websocketChannel, *webs
} }
return return
}, },
"getTransaction": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) {
r := struct {
Txid string `json:"txid"`
}{}
err = json.Unmarshal(req.Params, &r)
if err == nil {
rv, err = s.getTransaction(r.Txid)
}
return
},
"estimateFee": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) { "estimateFee": func(s *WebsocketServer, c *websocketChannel, req *websocketReq) (rv interface{}, err error) {
return s.estimateFee(c, req.Params) return s.estimateFee(c, req.Params)
}, },
@ -360,6 +370,10 @@ func (s *WebsocketServer) getAccountUtxo(descriptor string) (interface{}, error)
return s.api.GetAddressUtxo(descriptor, false) return s.api.GetAddressUtxo(descriptor, false)
} }
func (s *WebsocketServer) getTransaction(txid string) (interface{}, error) {
return s.api.GetTransaction(txid, false, false)
}
func (s *WebsocketServer) getInfo() (interface{}, error) { func (s *WebsocketServer) getInfo() (interface{}, error) {
vi := common.GetVersionInfo() vi := common.GetVersionInfo()
height, hash, err := s.db.GetBestBlock() height, hash, err := s.db.GetBestBlock()

View File

@ -152,6 +152,17 @@
}); });
} }
function getTransaction() {
const txid = document.getElementById('getTransactionTxid').value.trim();
const method = 'getTransaction';
const params = {
txid,
};
send(method, params, function (result) {
document.getElementById('getTransactionResult').innerText = JSON.stringify(result).replace(/,/g, ", ");
});
}
function estimateFee() { function estimateFee() {
try { try {
var blocks = document.getElementById('estimateFeeBlocks').value.split(","); var blocks = document.getElementById('estimateFeeBlocks').value.split(",");
@ -292,7 +303,7 @@
</div> </div>
<div class="col-8"> <div class="col-8">
<div class="row" style="margin: 0;"> <div class="row" style="margin: 0;">
<input type="text" style="width: 79%" class="form-control" id="getAccountInfoDescriptor" value="0xba98d6a5ac827632e3457de7512d211e4ff7e8bd"> <input type="text" placeholder="descriptor" style="width: 79%" class="form-control" id="getAccountInfoDescriptor" value="0xba98d6a5ac827632e3457de7512d211e4ff7e8bd">
<select id="getAccountInfoDetails" style="width: 20%; margin-left: 5px;"> <select id="getAccountInfoDetails" style="width: 20%; margin-left: 5px;">
<option value="basic">Basic</option> <option value="basic">Basic</option>
<option value="balance">Balance</option> <option value="balance">Balance</option>
@ -319,7 +330,7 @@
</div> </div>
<div class="col-8"> <div class="col-8">
<div class="row" style="margin: 0;"> <div class="row" style="margin: 0;">
<input type="text" placeholder="descriptor" style="width: 79%" class="form-control" id="getAccountUtxoDescriptor" value="0xba98d6a5ac827632e3457de7512d211e4ff7e8bd"> <input type="text" placeholder="descriptor" class="form-control" id="getAccountUtxoDescriptor" value="0xba98d6a5ac827632e3457de7512d211e4ff7e8bd">
</div> </div>
</div> </div>
<div class="col form-inline"></div> <div class="col form-inline"></div>
@ -328,6 +339,21 @@
<div class="col" id="getAccountUtxoResult"> <div class="col" id="getAccountUtxoResult">
</div> </div>
</div> </div>
<div class="row">
<div class="col">
<input class="btn btn-secondary" type="button" value="getTransaction" onclick="getTransaction()">
</div>
<div class="col-8">
<div class="row" style="margin: 0;">
<input type="text" placeholder="txid" class="form-control" id="getTransactionTxid" value="0xb266c89f9bfefa4aa2fca4e65b7d6c918d5407f464be781c2803f3546d34a574">
</div>
</div>
<div class="col form-inline"></div>
</div>
<div class="row">
<div class="col" id="getTransactionResult">
</div>
</div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<input class="btn btn-secondary" type="button" value="estimateFee" onclick="estimateFee()"> <input class="btn btn-secondary" type="button" value="estimateFee" onclick="estimateFee()">