Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-friendly to Raw adress conversion/comparison #180

Closed
kvizyx opened this issue Apr 6, 2024 · 5 comments
Closed

User-friendly to Raw adress conversion/comparison #180

kvizyx opened this issue Apr 6, 2024 · 5 comments

Comments

@kvizyx
Copy link

kvizyx commented Apr 6, 2024

Hi! In a nutshell, i'm building an app that detect transactions from specific addresses set by user so i need to compare user-friendly addresses (that user send to app) with raw addresses from subscription channel:

senderUFAddr := "sender-user-friendly-address"

go api.SubscribeOnTransactions(context.Background(), receiverAddress, lastProcessedLT, transactions)

for tx := range transactions {
	if tx.IO.In == nil || tx.IO.In.Msg == nil {
		fmt.Println("not an in message")
		continue
	}

	internalMessage, ok := tx.IO.In.Msg.(*tlb.InternalMessage)
	if !ok {
		fmt.Println("not an internal message")
		continue
	}

	senderRawAddr := internalMessage.SrcAddr.String()

	lastProcessedLT = tx.LT
}

How can i do this comparison with tonutils or i have to implement it on my own?

@xssnick
Copy link
Owner

xssnick commented Apr 6, 2024

Hi, to make raw address you could do this way:

raw := fmt.Sprintf("%d:%x", internalMessage.SrcAddr.Workchain(), internalMessage.SrcAddr.Data())

@xssnick
Copy link
Owner

xssnick commented Apr 6, 2024

internalMessage.SrcAddr.String()

returns user friendly address

@kvizyx
Copy link
Author

kvizyx commented Apr 6, 2024

I think i didn't put it that way. When user want to detect transactions from some address and send it to the app (0QAqow_s3o17yQk8h6QXVvE0yw_7IVzohVK1qcHfTCx_wVe_ for example) then i need to compare SrcAddr of each transaction to this address to detect whether it's transaction from address that user gave to us or not. But when i get the address from the transaction it's a bit different from one that user sent (EQAqow_s3o17yQk8h6QXVvE0yw_7IVzohVK1qcHfTCx_wbHw for the address shown in the example above) so it's a problem for me how to compare them. If anything, I'm new to TON, so I apologize in advance if this is a stupid question :)

@xssnick
Copy link
Owner

xssnick commented Apr 6, 2024

This is because address flags, your address which starts from 0 is address with testnet and nonboubce flags, you could set flag to src address too using SetTestnetOnly(true) and SetBounce(false), then call String(), then they should be the same.

@kvizyx
Copy link
Author

kvizyx commented Apr 6, 2024

Thanks!

@kvizyx kvizyx closed this as completed Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants