btc: check if payee has wallet; allow sending to external addresses

This commit is contained in:
Isaac Visintainer 2021-04-19 19:48:52 -07:00 committed by ixv
parent f161ef69ec
commit e759050eb2
6 changed files with 140 additions and 23 deletions

View File

@ -150,11 +150,20 @@
(handle-provider-update:hc !<(update:bp q.cage.sign))
::
%json
?> ?=([%permitted @ ~] wire)
=/ who (slav %p i.t.wire)
:_ state
:~ [%give %fact ~[/all] cage.sign]
[%pass wire %agent [who %btc-provider] %leave ~]
?+ wire `state
[%check-payee @ ~]
=/ who (slav %p i.t.wire)
:_ state
:~ [%give %fact ~[/all] cage.sign]
[%pass wire %agent [who %btc-wallet] %leave ~]
==
::
[%permitted @ ~]
=/ who (slav %p i.t.wire)
:_ state
:~ [%give %fact ~[/all] cage.sign]
[%pass wire %agent [who %btc-provider] %leave ~]
==
==
==
[cards this]
@ -164,6 +173,18 @@
|= =path
^- (quip card _this)
?+ path (on-watch:def path)
[%check-payee @ ~]
=/ who (slav %p i.t.path)
?> =(who our.bowl)
=/ response=json
%+ frond:enjs:format 'checkPayee'
%- pairs:enjs:format
:~ ['hasWallet' b+?=(^ curr-xpub)]
['payee' (ship:enjs:format our.bowl)]
==
:_ this
[%give %fact ~ %json !>(response)]~
::
[%all ~]
?> (team:title our.bowl src.bowl)
=^ a=(unit address) state
@ -207,15 +228,20 @@
:~ [%pass /set-provider/[(scot %p host.u.prov)] %agent [host.u.prov %btc-provider] %leave ~]
sub-card
==
::
::
%check-provider
=/ pax /permitted/(scot %p provider.comm)
:_ state
[%pass pax %agent [provider.comm %btc-provider] %watch pax]~
::
::
%check-payee
=/ pax /check-payee/(scot %p payee.comm)
:_ state
[%pass pax %agent [payee.comm %btc-wallet] %watch pax]~
::
%set-current-wallet
(set-curr-xpub xpub.comm)
::
::
%add-wallet
?~ (~(has by walts) xpub.comm)
((slog ~[leaf+"xpub already in wallet"]) `state)
@ -224,7 +250,7 @@
=^ c1 state (init-batches xpub.comm (dec max-gap.w))
=^ c2 state (set-curr-xpub xpub.comm)
[(weld c1 c2) state]
::
::
%delete-wallet
=* cw curr-xpub.state
=? cw ?&(?=(^ cw) =(u.cw xpub.comm))
@ -232,9 +258,34 @@
=. scans (~(del by scans) [xpub.comm %0])
=. scans (~(del by scans) [xpub.comm %1])
`state(walts (~(del by walts) xpub.comm))
::
%init-payment-external
?: is-broadcasting ~|("Broadcasting a transaction" !!)
?~ curr-xpub ~|("btc-wallet: no curr-xpub set" !!)
::
:: overwrites any payment being built in poym
::
=/ uw (~(get by walts) u.curr-xpub)
?: ?|(?=(~ uw) ?!(scanned.u.uw))
~|("no wallet with xpub or wallet not scanned yet" !!)
=/ [tb=(unit txbu) chng=(unit sats)]
%~ with-change sut:bl
[u.uw eny.bowl block.btc-state ~ feyb.comm ~[[address.comm value.comm ~]]]
?~ tb
%- (slog ~[leaf+"insufficient balance or not enough confirmed balance"])
`state
=^ tb=(unit txbu) state
?~ chng `state
=/ [addr=address =idx w=walt]
~(nixt-address wad:bl u.uw %1)
:- `(~(add-output txb:bl u.tb) addr u.chng `(~(hdkey wad:bl w %1) idx))
state(walts (~(put by walts) u.curr-xpub w))
:_ state(poym tb)
?~ tb ~
%+ turn txis.u.tb
|= =txi
(poke-provider %raw-tx txid.utxo.txi)
::
:: overwrites any payment being built in poym
::
%init-payment
~| "Can't pay ourselves; no comets; can't do while tx is being signed"
?< =(src.bowl payee.comm)
@ -242,7 +293,7 @@
?< is-broadcasting
:_ state(poym ~, feybs (~(put by feybs) payee.comm feyb.comm))
~[(poke-peer payee.comm [%gen-pay-address value.comm])]
::
::
%broadcast-tx
?~ prov ~|("Provider not connected" !!)
=+ signed=(from-cord:hxb:bc txhex.comm)

View File

@ -11,9 +11,11 @@
%- of
:~ set-provider+ship
check-provider+ship
check-payee+ship
set-current-wallet+so
add-wallet+add-wallet
delete-wallet+so
init-payment-external+init-payment-external
init-payment+init-payment
broadcast-tx+so
gen-new-address+|=(json ~)
@ -30,6 +32,13 @@
confs+(mu ni)
==
::
++ init-payment-external
%- ot
:~ address+address
value+ni
feyb+ni
==
::
++ init-payment
%- ot
:~ payee+ship

View File

@ -14,9 +14,11 @@
+$ command
$% [%set-provider provider=ship]
[%check-provider provider=ship]
[%check-payee payee=ship]
[%set-current-wallet =xpub]
[%add-wallet =xpub =fprint scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)]
[%delete-wallet =xpub]
[%init-payment-external =address value=sats feyb=sats]
[%init-payment payee=ship value=sats feyb=sats]
[%broadcast-tx txhex=cord]
[%gen-new-address ~]

View File

@ -22,27 +22,73 @@ export default class Send extends Component {
denomAmount: '0.00',
satsAmount: '0',
payee: '',
checkingPatp: false,
payeeType: '',
ready: false,
};
this.initPayment = this.initPayment.bind(this);
this.checkPatp = this.checkPatp.bind(this);
this.checkPayee = this.checkPayee.bind(this);
}
checkPatp(e){
let ready = ob.isValidPatp(e.target.value);
this.setState({ready, payee: e.target.value});
checkPayee(e){
let payee = e.target.value;
let isPatp = ob.isValidPatp(payee);
let isAddress = true; //TODO: actual validation
if (isPatp) {
let command = {'check-payee': payee}
this.props.api.btcWalletCommand(command)
this.setState({
checkingPatp: true,
payeeType: 'ship',
payee,
});
} else if (isAddress) {
this.setState({
payee,
ready: true,
checkingPatp: false,
payeeType: 'address',
});
} else {
this.setState({
payee,
ready: false,
checkingPatp: false,
payeeType: '',
});
}
}
componentDidUpdate(prevProps, prevState) {
if (!this.state.ready && this.state.checkingPatp) {
if (this.props.shipWallets[this.state.payee.slice(1)]) {
this.setState({ready: true, checkingPatp: false});
}
}
}
initPayment() {
let command = {
'init-payment': {
'payee': this.state.payee,
'value': parseInt(this.state.satsAmount),
'feyb': 1,
if (this.state.payeeType === 'ship') {
let command = {
'init-payment': {
'payee': this.state.payee,
'value': parseInt(this.state.satsAmount),
'feyb': 1,
}
}
this.props.api.btcWalletCommand(command).then(res => this.setState({signing: true}));
} else if (this.state.payeeType === 'address') {
let command = {
'init-payment-external': {
'address': this.state.payee,
'value': parseInt(this.state.satsAmount),
'feyb': 1,
}
}
this.props.api.btcWalletCommand(command).then(res => this.setState({signing: true}));
}
this.props.api.btcWalletCommand(command).then(res => this.setState({signing: true}));
}
render() {
@ -98,7 +144,7 @@ export default class Send extends Component {
fontSize='14px'
placeholder='~sampel-palnet or BTC address'
value={payee}
onChange={this.checkPatp}
onChange={this.checkPayee}
/>
</Row>
<Row

View File

@ -6,6 +6,10 @@ export class UpdateReducer {
if (json.providerStatus) {
this.reduceProviderStatus(json.providerStatus, state);
}
if (json.checkPayee) {
console.log('update', json);
this.reduceCheckPayee(json.checkPayee, state);
}
if (json["change-provider"]) {
this.reduceChangeProvider(json["change-provider"], state);
}
@ -33,6 +37,10 @@ export class UpdateReducer {
state.providerPerms[json.provider] = json.permitted;
}
reduceCheckPayee(json, state) {
state.shipWallets[json.payee] = json.hasWallet;
}
reduceChangeProvider(json, state) {
state.provider = json;
}

View File

@ -5,6 +5,7 @@ class Store {
constructor() {
this.state = {
providerPerms: {},
shipWallets: {},
provider: null,
wallet: null,
balance: null,