Skip to content

Commit f880002

Browse files
stepansnigirevStepan Snigirev
andauthored
implement getaddressinfo (#53)
* implement getaddressinfo * fix iswatchonly --------- Co-authored-by: Stepan Snigirev <stepan@planqc.eu>
1 parent 53b4218 commit f880002

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
This is a electrum-adapter. It exposes a Bitcoin-Core style API while using an electron API in the backend. It might be useful in specific usecases, e.g. having better performance when connecting to a electrum-server via Tor. In order to do that, it needs a Database. Quite easily you can use a kind of builtin SQLite. Depending on your usecase, you might want to use an external DB.
44

5-
Note! Requires embit from master branch. (Still true?!)
65
## Modes of usage
76

87
This can be used either in standalone mode or as a specter-extension. The second option is probably the main use-case.
@@ -56,4 +55,4 @@ Before your create a PR, make sure to [blackify](https://github.com/psf/black) a
5655
there is a git [pre-commit hook](https://ljvmiranda921.github.io/notebook/2018/06/21/precommits-using-black-and-flake8/) which you can simply install like this:
5756
```
5857
pre-commit install
59-
```
58+
```

src/cryptoadvance/spectrum/spectrum.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,6 @@ def sync_script(self, script, state=None):
361361
) # not existing, how can we fix that?
362362
# new tx
363363
else:
364-
365364
tx_details = {
366365
"tx_hash": tx_magic,
367366
"blockhash": blockheader.get("blockhash"),
@@ -844,6 +843,46 @@ def getrawchangeaddress(self, wallet, address_type=None):
844843
# TODO: refill keypool, subscribe
845844
return desc.getscriptpubkey().address(self.network)
846845

846+
@walletrpc
847+
def getaddressinfo(self, wallet, address: str):
848+
ismine = False
849+
ischange = False
850+
iswatchonly = False
851+
scriptpubkey = EmbitScript.from_address(address)
852+
sc = Script.query.filter_by(
853+
script=scriptpubkey.data.hex(), wallet=wallet
854+
).first()
855+
if sc:
856+
ismine = sc.index is not None
857+
if ismine:
858+
ischange = sc.descriptor.internal
859+
iswatchonly = sc.descriptor.private_descriptor is None
860+
obj = {
861+
"address": address,
862+
"scriptPubKey": scriptpubkey.data.hex(),
863+
"ismine": ismine,
864+
"ischange": ischange,
865+
"solvable": ismine,
866+
"iswatchonly": iswatchonly,
867+
}
868+
if ismine:
869+
desc = sc.descriptor.get_descriptor()
870+
derived_desc = desc.derive(sc.index).to_public()
871+
# convert xpubs to pubs
872+
for k in derived_desc.keys:
873+
if k.is_extended:
874+
k.key = k.key.key
875+
obj.update(
876+
{
877+
"desc": add_checksum(str(derived_desc)),
878+
"parent_desc": add_checksum(str(desc.to_public())),
879+
}
880+
)
881+
obj["labels"] = []
882+
if sc and sc.label:
883+
obj["labels"] = [sc.label]
884+
return obj
885+
847886
@walletrpc
848887
def listlabels(self, wallet, purpose=None):
849888
return list(

0 commit comments

Comments
 (0)