Skip to content

Commit

Permalink
experiment with parsing logs for sender (#1870)
Browse files Browse the repository at this point in the history
  • Loading branch information
salzbrenner authored Dec 18, 2024
1 parent a9a7cc1 commit 42b4c3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions core/node/auth/auth_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ func NewChainAuthArgsForIsSpaceMember(spaceId shared.StreamId, userId string) *C

func NewChainAuthArgsForIsWalletLinked(
userId []byte,
walletAddress []byte,
receipt *BlockchainTransactionReceipt,
) *ChainAuthArgs {
return &ChainAuthArgs{
kind: chainAuthKindIsWalletLinked,
principal: common.BytesToAddress(userId),
walletAddress: common.BytesToAddress(walletAddress),
receipt: receipt,
}
}

Expand All @@ -113,7 +113,7 @@ type ChainAuthArgs struct {
principal common.Address
permission Permission
linkedWallets string // a serialized list of linked wallets to comply with the cache key constraints
walletAddress common.Address
receipt *BlockchainTransactionReceipt
}

func (args *ChainAuthArgs) Principal() common.Address {
Expand All @@ -122,14 +122,14 @@ func (args *ChainAuthArgs) Principal() common.Address {

func (args *ChainAuthArgs) String() string {
return fmt.Sprintf(
"ChainAuthArgs{kind: %d, spaceId: %s, channelId: %s, principal: %s, permission: %s, linkedWallets: %s, walletAddress: %s}",
"ChainAuthArgs{kind: %d, spaceId: %s, channelId: %s, principal: %s, permission: %s, linkedWallets: %s, receipt: %s}",
args.kind,
args.spaceId,
args.channelId,
args.principal.Hex(),
args.permission,
args.linkedWallets,
args.walletAddress.Hex(),
args.receipt,
)
}

Expand Down Expand Up @@ -1009,9 +1009,21 @@ func (ca *chainAuth) checkEntitlement(
// handle checking if the user is linked to a specific wallet
if args.kind == chainAuthKindIsWalletLinked {
for _, wallet := range wallets {
if wallet == args.walletAddress {
// Check the transaction sender (for regular transactions)
if bytes.Equal(args.receipt.From, wallet.Bytes()) {
return boolCacheResult(true), nil
}
// Check each log in the receipt
for _, logEntry := range args.receipt.Logs {
// The sender is typically in the first topic (after the event signature)
if len(logEntry.Topics) > 1 { // First topic is event signature, second is usually sender
// Convert the topic (which is 32 bytes) to an address (20 bytes) by taking the last 20 bytes
senderFromTopic := common.BytesToAddress(logEntry.Topics[1])
if bytes.Equal(senderFromTopic.Bytes(), wallet.Bytes()) {
return boolCacheResult(true), nil
}
}
}
}
return boolCacheResult(false), nil
}
Expand Down
2 changes: 1 addition & 1 deletion core/node/rules/can_add_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ func (ru *aeBlockchainTransactionRules) blockchainTransaction_ChainAuth() (*auth
}
args := auth.NewChainAuthArgsForIsWalletLinked(
ru.params.parsedEvent.Event.CreatorAddress,
ru.transaction.Receipt.From,
ru.transaction.Receipt,
)
return args, nil
}
Expand Down

0 comments on commit 42b4c3a

Please sign in to comment.