Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
How do you parse uints within TON transaction comments in the recv_internal function?

I have a simple transfer from a TON wallet to a contract. It has a comment: "2". Is there a way to parse this comment within the recv_internal function?

Here's what I tried:

() recv_internal(int balance, int msg_value, cell in_msg_full, slice in_msg_body) {
	int op = in_msg_body~load_uint(32);
	
	if (op == 0) {
		int comment = in_msg_body~load_uint(64);
		set_data(begin_cell().store_int(comment, 64).end_cell());
	}
}

Supposedly, if op is 0, then it is a transfer with a comment. But I haven't been able to store the uint properly. How do I do so?


This question was imported from Telegram Chat: https://t.me/tondev_eng/8057

  
  
Posted 11 months ago
Votes Newest

Answers


This is the right track, you do need to check 0. And you are loading in op correctly. But the way that you work with the comment is incorrect.

The characters are coded within UTF-8, so using load_uint will not work as expected, since it expects binary encoding.

Instead, you will have to parse it:

() recv_internal(int balance, int msg_value, cell in_msg_full, slice in_msg_body) {
	int op = in_msg_body~load_uint(32);
	
	if (op == 0) {
		;; load in the first 8 bits because of UTF-8 encoding
		int comment = in_msg_body~load_uint(8);
		
		;; in UTF-8, 50 is the character for 2, because 50 = 0x32
		var state = 0;
		if (comment == 50) {
			state = 2;
		}
		set_data(begin_cell().store_uint(op, 32).store_uint(comment, 8).store_int(state, 8).end_cell());
	}
}

Refer to UTF-8 here: https://www.utf8-chartable.de/

  
  
Posted 11 months ago
Jeremy
384 × 5 Administrator
5K Views
1 Answer
11 months ago
11 months ago
Tags
Similar posts