mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-17 04:04:21 +01:00
* [server] descriptor-based vtxo script * [server] fix unit tests * [sdk] descriptor based vtxo * empty config check & version flag support * fix: empty config check & version flag support (#309) * fix * [sdk] several fixes * [sdk][server] several fixes * [common][sdk] add reversible VtxoScript type, use it in async payment * [common] improve parser * [common] fix reversible vtxo parser * [sdk] remove logs * fix forfeit map * remove debug log * [sdk] do not allow reversible vtxo script in case of self-transfer * remove signing pubkey * remove signer public key, craft forfeit txs client side * go work sync * fix linter errors * rename MakeForfeitTxs to BuildForfeitTxs * fix conflicts * fix tests * comment VtxoScript type * revert ROUND_INTERVAL value --------- Co-authored-by: Pietralberto Mazza <18440657+altafan@users.noreply.github.com> Co-authored-by: sekulicd <sekula87@gmail.com>
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
arkv1 "github.com/ark-network/ark/api-spec/protobuf/gen/ark/v1"
|
|
"github.com/ark-network/ark/common"
|
|
"github.com/ark-network/ark/server/internal/core/domain"
|
|
"github.com/ark-network/ark/server/internal/core/ports"
|
|
"github.com/decred/dcrd/dcrec/secp256k1/v4"
|
|
)
|
|
|
|
func parseAddress(addr string) (string, *secp256k1.PublicKey, *secp256k1.PublicKey, error) {
|
|
if len(addr) <= 0 {
|
|
return "", nil, nil, fmt.Errorf("missing address")
|
|
}
|
|
return common.DecodeAddress(addr)
|
|
}
|
|
|
|
func parseInputs(ins []*arkv1.Input) ([]ports.Input, error) {
|
|
if len(ins) <= 0 {
|
|
return nil, fmt.Errorf("missing inputs")
|
|
}
|
|
|
|
inputs := make([]ports.Input, 0, len(ins))
|
|
for _, input := range ins {
|
|
inputs = append(inputs, ports.Input{
|
|
VtxoKey: domain.VtxoKey{
|
|
Txid: input.GetOutpoint().GetTxid(),
|
|
VOut: input.GetOutpoint().GetVout(),
|
|
},
|
|
Descriptor: input.GetDescriptor_(),
|
|
})
|
|
}
|
|
|
|
return inputs, nil
|
|
}
|
|
|
|
func parseReceivers(outs []*arkv1.Output) ([]domain.Receiver, error) {
|
|
receivers := make([]domain.Receiver, 0, len(outs))
|
|
for _, out := range outs {
|
|
if out.GetAmount() == 0 {
|
|
return nil, fmt.Errorf("missing output amount")
|
|
}
|
|
if len(out.GetAddress()) <= 0 && len(out.GetDescriptor_()) <= 0 {
|
|
return nil, fmt.Errorf("missing output destination")
|
|
}
|
|
|
|
receivers = append(receivers, domain.Receiver{
|
|
Descriptor: out.GetDescriptor_(),
|
|
Amount: out.GetAmount(),
|
|
OnchainAddress: out.GetAddress(),
|
|
})
|
|
}
|
|
return receivers, nil
|
|
}
|
|
|
|
func toRoundStage(stage domain.Stage) arkv1.RoundStage {
|
|
if stage.Failed {
|
|
return arkv1.RoundStage_ROUND_STAGE_FAILED
|
|
}
|
|
|
|
switch stage.Code {
|
|
case domain.RegistrationStage:
|
|
return arkv1.RoundStage_ROUND_STAGE_REGISTRATION
|
|
case domain.FinalizationStage:
|
|
if stage.Ended {
|
|
return arkv1.RoundStage_ROUND_STAGE_FINALIZED
|
|
}
|
|
return arkv1.RoundStage_ROUND_STAGE_FINALIZATION
|
|
default:
|
|
return arkv1.RoundStage_ROUND_STAGE_UNSPECIFIED
|
|
}
|
|
}
|