mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 20:54:20 +01:00
New address encoding (#356)
* [common] rework address encoding * new address encoding * replace offchain address by vtxo output key in DB * merge migrations files into init one * fix txbuilder fixtures * fix transaction events
This commit is contained in:
@@ -84,6 +84,7 @@ func (b *txBuilder) BuildSweepTx(inputs []ports.SweepInput) (signedSweepTx strin
|
||||
func (b *txBuilder) BuildForfeitTxs(
|
||||
poolTx string,
|
||||
payments []domain.Payment,
|
||||
descriptors map[domain.VtxoKey]string,
|
||||
minRelayFeeRate chainfee.SatPerKVByte,
|
||||
) (connectors []string, forfeitTxs []string, err error) {
|
||||
connectorAddress, err := b.getConnectorAddress(poolTx)
|
||||
@@ -106,7 +107,7 @@ func (b *txBuilder) BuildForfeitTxs(
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
forfeitTxs, err = b.createForfeitTxs(payments, connectorTxs, connectorAmount, minRelayFeeRate)
|
||||
forfeitTxs, err = b.createForfeitTxs(payments, descriptors, connectorTxs, connectorAmount, minRelayFeeRate)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -147,13 +148,13 @@ func (b *txBuilder) BuildRoundTx(
|
||||
return "", nil, "", err
|
||||
}
|
||||
|
||||
receivers, err := getOffchainReceivers(payments)
|
||||
vtxosLeaves, err := getOutputVtxosLeaves(payments)
|
||||
if err != nil {
|
||||
return "", nil, "", err
|
||||
}
|
||||
|
||||
treeFactoryFn, sharedOutputScript, sharedOutputAmount, err = tree.CraftCongestionTree(
|
||||
b.onchainNetwork().AssetID, aspPubkey, receivers, feeSatsPerNode, b.roundLifetime,
|
||||
b.onchainNetwork().AssetID, aspPubkey, vtxosLeaves, feeSatsPerNode, b.roundLifetime,
|
||||
)
|
||||
if err != nil {
|
||||
return "", nil, "", err
|
||||
@@ -362,7 +363,10 @@ func (b *txBuilder) FindLeaves(
|
||||
}
|
||||
|
||||
func (b *txBuilder) BuildAsyncPaymentTransactions(
|
||||
_ []domain.Vtxo, _ *secp256k1.PublicKey, _ []domain.Receiver,
|
||||
_ []domain.Vtxo,
|
||||
_ map[domain.VtxoKey]string,
|
||||
_ map[domain.VtxoKey]chainhash.Hash,
|
||||
_ []domain.Receiver,
|
||||
) (string, error) {
|
||||
return "", fmt.Errorf("not implemented")
|
||||
}
|
||||
@@ -396,7 +400,6 @@ func (b *txBuilder) createPoolTx(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
receivers := getOnchainReceivers(payments)
|
||||
nbOfInputs := countSpentVtxos(payments)
|
||||
connectorsAmount := (dustAmount + connectorMinRelayFee) * nbOfInputs
|
||||
if nbOfInputs > 1 {
|
||||
@@ -424,21 +427,17 @@ func (b *txBuilder) createPoolTx(
|
||||
})
|
||||
}
|
||||
|
||||
for _, receiver := range receivers {
|
||||
targetAmount += receiver.Amount
|
||||
|
||||
receiverScript, err := address.ToOutputScript(receiver.OnchainAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
outputs = append(outputs, psetv2.OutputArgs{
|
||||
Asset: b.onchainNetwork().AssetID,
|
||||
Amount: receiver.Amount,
|
||||
Script: receiverScript,
|
||||
})
|
||||
onchainOutputs, err := getOnchainOutputs(payments, b.onchainNetwork())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, out := range onchainOutputs {
|
||||
targetAmount += out.Amount
|
||||
}
|
||||
|
||||
outputs = append(outputs, onchainOutputs...)
|
||||
|
||||
for _, in := range boardingInputs {
|
||||
targetAmount -= in.Amount
|
||||
}
|
||||
@@ -786,6 +785,7 @@ func (b *txBuilder) createConnectors(
|
||||
|
||||
func (b *txBuilder) createForfeitTxs(
|
||||
payments []domain.Payment,
|
||||
descriptors map[domain.VtxoKey]string,
|
||||
connectors []*psetv2.Pset,
|
||||
connectorAmount uint64,
|
||||
minRelayFeeRate chainfee.SatPerKVByte,
|
||||
@@ -803,7 +803,12 @@ func (b *txBuilder) createForfeitTxs(
|
||||
forfeitTxs := make([]string, 0)
|
||||
for _, payment := range payments {
|
||||
for _, vtxo := range payment.Inputs {
|
||||
offchainScript, err := tree.ParseVtxoScript(vtxo.Descriptor)
|
||||
desc, ok := descriptors[vtxo.VtxoKey]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("descriptor not found for vtxo %s:%d", vtxo.VtxoKey.Txid, vtxo.VtxoKey.VOut)
|
||||
}
|
||||
|
||||
offchainScript, err := tree.ParseVtxoScript(desc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user