mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 20:54:20 +01:00
Add CreatePayment and CompletePayment (#229)
Co-authored-by: Marco Argentieri <tiero@users.noreply.github.com> * Add claim command * Persist pending data in sqlite repo * Remove debug log * Return pending data at interface level * Fix unlocking btc wallet after restart * Lint & Fix whitelist permissions * Fix send command for covenant * Update client/covenantless/claim.go Signed-off-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> * Fix * Pay for min relay fee instead of estimating fees for redeem and unconf forfeit txs * Add support for pending payments (coventanless) * Fixes * Fixes * Improve verbosity * Fix coin selection * Fix --------- Signed-off-by: Marco Argentieri <3596602+tiero@users.noreply.github.com> Co-authored-by: louisinger <louis@vulpem.com> Co-authored-by: Marco Argentieri <tiero@users.noreply.github.com> Co-authored-by: Marco Argentieri <3596602+tiero@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
57ce08f239
commit
72a7f29bab
@@ -180,14 +180,24 @@ func (a *restClient) ListVtxos(
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
var redeemTx string
|
||||
var uncondForfeitTxs []string
|
||||
if v.PendingData != nil {
|
||||
redeemTx = v.PendingData.RedeemTx
|
||||
uncondForfeitTxs = v.PendingData.UnconditionalForfeitTxs
|
||||
}
|
||||
|
||||
spendableVtxos = append(spendableVtxos, client.Vtxo{
|
||||
VtxoKey: client.VtxoKey{
|
||||
Txid: v.Outpoint.Txid,
|
||||
VOut: uint32(v.Outpoint.Vout),
|
||||
},
|
||||
Amount: uint64(amount),
|
||||
RoundTxid: v.PoolTxid,
|
||||
ExpiresAt: expiresAt,
|
||||
Amount: uint64(amount),
|
||||
RoundTxid: v.PoolTxid,
|
||||
ExpiresAt: expiresAt,
|
||||
Pending: v.Pending,
|
||||
RedeemTx: redeemTx,
|
||||
UnconditionalForfeitTxs: uncondForfeitTxs,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -358,6 +368,53 @@ func (a *restClient) FinalizePayment(
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *restClient) CreatePayment(
|
||||
ctx context.Context, inputs []client.VtxoKey, outputs []client.Output,
|
||||
) (string, []string, error) {
|
||||
ins := make([]*models.V1Input, 0, len(inputs))
|
||||
for _, i := range inputs {
|
||||
ins = append(ins, &models.V1Input{
|
||||
Txid: i.Txid,
|
||||
Vout: int64(i.VOut),
|
||||
})
|
||||
}
|
||||
outs := make([]*models.V1Output, 0, len(outputs))
|
||||
for _, o := range outputs {
|
||||
outs = append(outs, &models.V1Output{
|
||||
Address: o.Address,
|
||||
Amount: strconv.Itoa(int(o.Amount)),
|
||||
})
|
||||
}
|
||||
body := models.V1CreatePaymentRequest{
|
||||
Inputs: ins,
|
||||
Outputs: outs,
|
||||
}
|
||||
resp, err := a.svc.ArkServiceCreatePayment(
|
||||
ark_service.NewArkServiceCreatePaymentParams().WithBody(&body),
|
||||
)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
return resp.GetPayload().SignedRedeemTx, resp.GetPayload().UsignedUnconditionalForfeitTxs, nil
|
||||
}
|
||||
|
||||
func (a *restClient) CompletePayment(
|
||||
ctx context.Context, signedRedeemTx string, signedUnconditionalForfeitTxs []string,
|
||||
) error {
|
||||
req := &arkv1.CompletePaymentRequest{
|
||||
SignedRedeemTx: signedRedeemTx,
|
||||
SignedUnconditionalForfeitTxs: signedUnconditionalForfeitTxs,
|
||||
}
|
||||
body := models.V1CompletePaymentRequest{
|
||||
SignedRedeemTx: req.GetSignedRedeemTx(),
|
||||
SignedUnconditionalForfeitTxs: req.GetSignedUnconditionalForfeitTxs(),
|
||||
}
|
||||
_, err := a.svc.ArkServiceCompletePayment(
|
||||
ark_service.NewArkServiceCompletePaymentParams().WithBody(&body),
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (a *restClient) GetRoundByID(
|
||||
ctx context.Context, roundID string,
|
||||
) (*client.Round, error) {
|
||||
|
||||
Reference in New Issue
Block a user