Last active
May 24, 2018 09:23
-
-
Save n1bor/8077fe11206041a571754e3e4ff91f13 to your computer and use it in GitHub Desktop.
Regen Tx from data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package fr.acinq.eclair | |
import grizzled.slf4j.Logging | |
import fr.acinq.bitcoin.{BinaryData, OutPoint, Transaction} | |
import fr.acinq.eclair.wire.ChannelCodecs.{stateDataCodec,DATA_CLOSING_Codec} | |
import scodec.bits.BitVector | |
import fr.acinq.eclair.channel.HasCommitments | |
import fr.acinq.eclair.crypto.LocalKeyManager | |
import fr.acinq.eclair.channel.Helpers | |
import akka.actor.ActorSystem | |
import akka.actor.ActorLogging | |
import akka.actor.Actor | |
import akka.actor.Props | |
import fr.acinq.eclair.blockchain.fee.{FeeratesPerKB,FeeratesPerKw} | |
import akka.pattern.ask | |
import scala.concurrent.duration._ | |
import akka.util.Timeout | |
import java.nio.file.Files | |
import java.io.File | |
/** | |
* Created by PM on 25/01/2016. | |
*/ | |
case class Message(local: Boolean, seedHex: String, channelHex: String) | |
object RecreateTx extends App with Logging { | |
logger.info("started") | |
if (args.length != 2) { | |
println("Please pass true/false if local and then channel data as hex") | |
/** | |
sqlite3 eclair.sqlite | |
select quote(data) from local_channels where channel_id=x'yourchannelidinHEX'; | |
**/ | |
System.exit(1) | |
} | |
println("Please enter seed:") | |
/** | |
xxd -p seed.dat | |
But paste in as one string without the newline I seemed to get! | |
**/ | |
val seedInput=scala.io.StdIn.readLine() | |
implicit val system = ActorSystem() | |
implicit val log = system.log | |
val helloActor = system.actorOf(Props[HelloActor], name = "helloactor") | |
val defaultFeerates = FeeratesPerKB( | |
block_1 = 1000, | |
blocks_2 = 1000, | |
blocks_6 = 2000, | |
blocks_12 = 1000, | |
blocks_36 = 1000, | |
blocks_72 = 1000 | |
) | |
Globals.feeratesPerKB.set(defaultFeerates) | |
Globals.feeratesPerKw.set(FeeratesPerKw(defaultFeerates)) | |
log.info(Globals.feeratesPerKw.get.blocks_6.toString()) | |
implicit val timeout = Timeout(5 seconds) | |
helloActor ? Message(args(0).toBoolean, seedInput, args(1)) | |
} | |
class HelloActor extends Actor with ActorLogging { | |
implicit def implicitLog = log | |
def receive = { | |
case m :Message => { | |
val seed=BinaryData(m.seedHex).data | |
val channelHex = m.channelHex | |
log.info("Data is: "+channelHex) | |
val channelBinary=BinaryData(channelHex) | |
log.info("Data is: "+channelBinary) | |
val hasCommitments=Some(DATA_CLOSING_Codec.decode(BitVector(channelBinary.data.drop(3))).require.value) | |
log.info("Data is: "+hasCommitments) | |
log.info("Channel id is: "+hasCommitments.get.channelId.toString()) | |
log.info("seed"+seed.toString()) | |
val keyManager = new LocalKeyManager(seed, NodeParams.makeChainHash("mainnet")) | |
println(keyManager.nodeId.toString()) | |
if(m.local) { | |
val com=Helpers.Closing.claimCurrentLocalCommitTxOutputs(keyManager, hasCommitments.get.commitments, hasCommitments.get.commitments.localCommit.publishableTxs.commitTx.tx) | |
log.info(com.toString) | |
log.info(com.claimMainDelayedOutputTx.head.toString()) | |
} else { | |
val com=Helpers.Closing.claimRemoteCommitMainOutput(keyManager, hasCommitments.get.commitments, hasCommitments.get.commitments.remoteCommit.remotePerCommitmentPoint.value, | |
hasCommitments.get.remoteCommitPublished.get.commitTx) | |
log.info(com.toString) | |
log.info(com.claimMainOutputTx.head.toString()) | |
} | |
sender ! "Done" | |
} | |
case _ => println("huh?") | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment