mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-24 06:47:46 +01:00
Electrum: add data to TxIdFromPosResponse. (#1038)
To make the response usable, we need to copy the request input (block height and transaction position).
This commit is contained in:
parent
cb1196cf95
commit
a53145a6da
2 changed files with 7 additions and 11 deletions
|
@ -381,7 +381,7 @@ object ElectrumClient {
|
||||||
case class BroadcastTransactionResponse(tx: Transaction, error: Option[Error]) extends Response
|
case class BroadcastTransactionResponse(tx: Transaction, error: Option[Error]) extends Response
|
||||||
|
|
||||||
case class GetTransactionIdFromPosition(height: Int, tx_pos: Int, merkle: Boolean = false) extends Request
|
case class GetTransactionIdFromPosition(height: Int, tx_pos: Int, merkle: Boolean = false) extends Request
|
||||||
case class GetTransactionIdFromPositionResponse(txid: ByteVector32, merkle: Seq[ByteVector32]) extends Response
|
case class GetTransactionIdFromPositionResponse(txid: ByteVector32, height: Int, tx_pos: Int, merkle: Seq[ByteVector32]) extends Response
|
||||||
|
|
||||||
case class GetTransaction(txid: ByteVector32) extends Request
|
case class GetTransaction(txid: ByteVector32) extends Request
|
||||||
case class GetTransactionResponse(tx: Transaction) extends Response
|
case class GetTransactionResponse(tx: Transaction) extends Response
|
||||||
|
@ -593,14 +593,14 @@ object ElectrumClient {
|
||||||
UnspentItem(ByteVector32.fromValidHex(tx_hash), tx_pos, value, height)
|
UnspentItem(ByteVector32.fromValidHex(tx_hash), tx_pos, value, height)
|
||||||
})
|
})
|
||||||
ScriptHashListUnspentResponse(scripthash, items)
|
ScriptHashListUnspentResponse(scripthash, items)
|
||||||
case GetTransactionIdFromPosition(_, _, false) =>
|
case GetTransactionIdFromPosition(height, tx_pos, false) =>
|
||||||
val JString(tx_hash) = json.result
|
val JString(tx_hash) = json.result
|
||||||
GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), Nil)
|
GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), height, tx_pos, Nil)
|
||||||
case GetTransactionIdFromPosition(_, _, true) =>
|
case GetTransactionIdFromPosition(height, tx_pos, true) =>
|
||||||
val JString(tx_hash) = json.result \ "tx_hash"
|
val JString(tx_hash) = json.result \ "tx_hash"
|
||||||
val JArray(hashes) = json.result \ "merkle"
|
val JArray(hashes) = json.result \ "merkle"
|
||||||
val leaves = hashes collect { case JString(value) => ByteVector32.fromValidHex(value) }
|
val leaves = hashes collect { case JString(value) => ByteVector32.fromValidHex(value) }
|
||||||
GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), leaves)
|
GetTransactionIdFromPositionResponse(ByteVector32.fromValidHex(tx_hash), height, tx_pos, leaves)
|
||||||
case GetTransaction(_) =>
|
case GetTransaction(_) =>
|
||||||
val JString(hex) = json.result
|
val JString(hex) = json.result
|
||||||
GetTransactionResponse(Transaction.read(hex))
|
GetTransactionResponse(Transaction.read(hex))
|
||||||
|
|
|
@ -69,16 +69,12 @@ class ElectrumClientSpec extends TestKit(ActorSystem("test")) with FunSuiteLike
|
||||||
|
|
||||||
test("get transaction id from position") {
|
test("get transaction id from position") {
|
||||||
probe.send(client, GetTransactionIdFromPosition(height, position))
|
probe.send(client, GetTransactionIdFromPosition(height, position))
|
||||||
val GetTransactionIdFromPositionResponse(txid, merkle) = probe.expectMsgType[GetTransactionIdFromPositionResponse]
|
probe.expectMsg(GetTransactionIdFromPositionResponse(referenceTx.txid, height, position, Nil))
|
||||||
assert(txid === referenceTx.txid)
|
|
||||||
assert(merkle === Nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("get transaction id from position with merkle proof") {
|
test("get transaction id from position with merkle proof") {
|
||||||
probe.send(client, GetTransactionIdFromPosition(height, position, merkle = true))
|
probe.send(client, GetTransactionIdFromPosition(height, position, merkle = true))
|
||||||
val GetTransactionIdFromPositionResponse(txid, merkle) = probe.expectMsgType[GetTransactionIdFromPositionResponse]
|
probe.expectMsg(GetTransactionIdFromPositionResponse(referenceTx.txid, height, position, merkleProof))
|
||||||
assert(txid === referenceTx.txid)
|
|
||||||
assert(merkle === merkleProof)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
test("get transaction") {
|
test("get transaction") {
|
||||||
|
|
Loading…
Add table
Reference in a new issue