Skip to content

Commit

Permalink
Add lookup()
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrguric committed Dec 16, 2023
1 parent 99c9cd3 commit ded90df
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ $installedHooksStats = $TxHookParser->installedHooksStats();
# List of modified hooks
$modifiedHooks = $TxHookParser->modifiedHooks();

# Manual data lookup (lookup any combination of mapped data)
$lookup = $TxHookParser->lookup('raddress...','Hook','installed');

```

### HookOn field
Expand Down
14 changes: 14 additions & 0 deletions src/TxHookParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ public function accounts(): array
return \array_keys($data);
}

/**
* Lookup map by address type and event respectivly
* from data added by addHook() method.
* @param ?string $address - null to lookup hooks without account context
* @param string $fromType
* @param string $event
* @return array
*/
public function lookup(?string $address, string $fromType, string $event): array
{
$address = $address !== null ? $address:'NULL';
return isset($this->map_full[$address][$fromType][$event]) ? $this->map_full[$address][$fromType][$event]:[];
}

/**
* Get list of hooks of affected provided account.
* @return array
Expand Down
19 changes: 19 additions & 0 deletions tests/Tx01Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ public function testEnableAmendment()
'r6QZ6zfK37ZSec5hWiQDtbTxUaU2NWG3F',
'r4FRPZbLnyuVeGiSi1Ap6uaaPvPXYZh1XN',
], $hookAccounts);

$lookupTestUnknown = $TxHookParser->lookup('rAAAAAAAAAAAAAAAAAAAAAAAAAAAA','a','b');
$this->assertIsArray($lookupTestUnknown);
$this->assertEquals([], $lookupTestUnknown);

$lookupTestUnknown2 = $TxHookParser->lookup('rwyypATD1dQxDbdQjMvrqnsHr2cQw5rjMh','a','b');
$this->assertIsArray($lookupTestUnknown2);
$this->assertEquals([], $lookupTestUnknown2);

$lookupTestUnknown3 = $TxHookParser->lookup('rwyypATD1dQxDbdQjMvrqnsHr2cQw5rjMh','Hook','b');
$this->assertIsArray($lookupTestUnknown3);
$this->assertEquals([], $lookupTestUnknown3);

//This lookup should return list of hooks installed on specific account
$lookupTest = $TxHookParser->lookup('rwyypATD1dQxDbdQjMvrqnsHr2cQw5rjMh','Hook','installed');
$this->assertIsArray($lookupTest);
$this->assertEquals([
'5EDF6439C47C423EAC99C1061EE2A0CE6A24A58C8E8A66E4B3AF91D76772DC77'
], $lookupTest);
}

public function testEnableAmendmentCreatedHooks()
Expand Down

0 comments on commit ded90df

Please sign in to comment.