Skip to content

Commit

Permalink
RPC: Fix de-serializing null values in topic lists (DeFiCh#2807)
Browse files Browse the repository at this point in the history
* Enable passing null value in topic list
  • Loading branch information
sieniven authored Jan 29, 2024
1 parent 4d7e2dd commit 6b97eb8
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 27 deletions.
6 changes: 3 additions & 3 deletions contrib/linearize/linearize-data.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,9 @@ def run(self):
if "netmagic" not in settings:
settings["netmagic"] = "f9beb4d9"
if "genesis" not in settings:
settings[
"genesis"
] = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
settings["genesis"] = (
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
)
if "input" not in settings:
settings["input"] = "input"
if "hashlist" not in settings:
Expand Down
4 changes: 2 additions & 2 deletions lib/ain-grpc/src/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ pub struct GetLogsRequest {
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LogRequestTopics {
VecOfHashes(Vec<H256>),
VecOfHashVecs(Vec<Vec<H256>>),
VecOfHashes(Vec<Option<H256>>),
VecOfHashVecs(Vec<Vec<Option<H256>>>),
}
14 changes: 10 additions & 4 deletions lib/ain-grpc/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,12 @@ impl MetachainRPCServer for MetachainRPCModule {
};
let topics = input.topics.map(|topics| match topics {
LogRequestTopics::VecOfHashes(inputs) => {
inputs.into_iter().map(|input| vec![input]).collect()
inputs.iter().flatten().map(|input| vec![*input]).collect()
}
LogRequestTopics::VecOfHashVecs(inputs) => inputs,
LogRequestTopics::VecOfHashVecs(inputs) => inputs
.iter()
.map(|hashes| hashes.iter().flatten().copied().collect())
.collect(),
});
let curr_block = self.get_block(Some(BlockNumber::Latest))?.header.number;
let mut criteria = FilterCriteria {
Expand Down Expand Up @@ -1075,9 +1078,12 @@ impl MetachainRPCServer for MetachainRPCModule {
};
let topics = input.topics.map(|topics| match topics {
LogRequestTopics::VecOfHashes(inputs) => {
inputs.into_iter().map(|input| vec![input]).collect()
inputs.iter().flatten().map(|input| vec![*input]).collect()
}
LogRequestTopics::VecOfHashVecs(inputs) => inputs,
LogRequestTopics::VecOfHashVecs(inputs) => inputs
.iter()
.map(|hashes| hashes.iter().flatten().copied().collect())
.collect(),
});
let curr_block = self.get_block(Some(BlockNumber::Latest))?.header.number;
let mut criteria = FilterCriteria {
Expand Down
6 changes: 3 additions & 3 deletions test/functional/feature_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -1297,9 +1297,9 @@ def run_test(self):
b76 = self.next_block(76)
size = MAX_BLOCK_SIGOPS - 1 + MAX_SCRIPT_ELEMENT_SIZE + 1 + 5
a = bytearray([OP_CHECKSIG] * size)
a[
MAX_BLOCK_SIGOPS - 1
] = 0x4E # PUSHDATA4, but leave the following bytes as just checksigs
a[MAX_BLOCK_SIGOPS - 1] = (
0x4E # PUSHDATA4, but leave the following bytes as just checksigs
)
tx = self.create_and_sign_transaction(out[23], 1, CScript(a))
b76 = self.update_block(76, [tx])
self.send_blocks([b76], True)
Expand Down
8 changes: 5 additions & 3 deletions test/functional/feature_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ def run_test(self):
block_count = 10
blocks = self.nodes[1].generate(
nblocks=block_count,
address=self.nodes[1].getnewaddress()
if self.is_wallet_compiled()
else ADDRESS_BCRT1_UNSPENDABLE,
address=(
self.nodes[1].getnewaddress()
if self.is_wallet_compiled()
else ADDRESS_BCRT1_UNSPENDABLE
),
)

# wait at most 10 seconds for expected number of files before reading the content
Expand Down
12 changes: 6 additions & 6 deletions test/functional/mempool_accept.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ def run_test(self):
"A transaction with missing inputs, that existed once in the past"
)
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_0)))
tx.vin[
0
].prevout.n = 1 # Set vout to 1, to spend the other outpoint (49 coins) of the in-chain-tx we want to double spend
tx.vin[0].prevout.n = (
1 # Set vout to 1, to spend the other outpoint (49 coins) of the in-chain-tx we want to double spend
)
raw_tx_1 = node.signrawtransactionwithwallet(tx.serialize().hex())["hex"]
txid_1 = node.sendrawtransaction(hexstring=raw_tx_1, maxfeerate=0)
# Now spend both to "clearly hide" the outputs, ie. remove the coins from the utxo set by spending them
Expand Down Expand Up @@ -445,9 +445,9 @@ def run_test(self):

self.log.info("A transaction that is locked by BIP68 sequence logic")
tx.deserialize(BytesIO(hex_str_to_bytes(raw_tx_reference)))
tx.vin[
0
].nSequence = 2 # We could include it in the second block mined from now, but not the very next one
tx.vin[0].nSequence = (
2 # We could include it in the second block mined from now, but not the very next one
)
# Can skip re-signing the tx because of early rejection
self.check_mempool_result(
result_expected=[
Expand Down
6 changes: 3 additions & 3 deletions test/functional/p2p_segwit.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ def test_standardness_v0(self):
tx.vin = [CTxIn(COutPoint(p2sh_tx.sha256, 0), CScript([witness_program]))]
tx.vout = [CTxOut(p2sh_tx.vout[0].nValue - 10000, script_pubkey)]
tx.vout.append(CTxOut(8000, script_pubkey)) # Might burn this later
tx.vin[
0
].nSequence = BIP125_SEQUENCE_NUMBER # Just to have the option to bump this tx from the mempool
tx.vin[0].nSequence = (
BIP125_SEQUENCE_NUMBER # Just to have the option to bump this tx from the mempool
)
tx.rehash()

# This is always accepted, since the mempool policy is to consider segwit as always active
Expand Down
8 changes: 5 additions & 3 deletions test/functional/wallet_import_rescan.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def do_import(self, timestamp):

elif self.call in (Call.multiaddress, Call.multiscript):
request = {
"scriptPubKey": {"address": self.address["address"]}
if self.call == Call.multiaddress
else self.address["scriptPubKey"],
"scriptPubKey": (
{"address": self.address["address"]}
if self.call == Call.multiaddress
else self.address["scriptPubKey"]
),
"timestamp": timestamp
+ TIMESTAMP_WINDOW
+ (1 if self.rescan == Rescan.late_timestamp else 0),
Expand Down

0 comments on commit 6b97eb8

Please sign in to comment.