-
Notifications
You must be signed in to change notification settings - Fork 115
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
Support for the Finalized W5 (V5R1) Contract #210
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fb48bfa
Refactor V5R1 to V5Beta and Prepare Support for V5 Final (WIP)
Totemancer 0fedda1
Update to Finalized V5 Contract (WIP)
Totemancer 8ba6af6
Update name to V5R1, V5R2
Totemancer d1d8590
Add comments near the wallet versions
Totemancer 1cbd66d
Finalized V5 Contract Integration
Totemancer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package wallet | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/xssnick/tonutils-go/tlb" | ||
"github.com/xssnick/tonutils-go/ton" | ||
|
||
"github.com/xssnick/tonutils-go/tvm/cell" | ||
) | ||
|
||
// https://github.com/tonkeeper/tonkeeper-ton/commit/e8a7f3415e241daf4ac723f273fbc12776663c49#diff-c20d462b2e1ec616bbba2db39acc7a6c61edc3d5e768f5c2034a80169b1a56caR29 | ||
const _V5BetaCodeHex = "b5ee9c7241010101002300084202e4cf3b2f4c6d6a61ea0f2b5447d266785b26af3637db2deee6bcd1aa826f34120dcd8e11" | ||
|
||
type ConfigV5Beta struct { | ||
NetworkGlobalID int32 | ||
Workchain int8 | ||
} | ||
|
||
type SpecV5Beta struct { | ||
SpecRegular | ||
SpecSeqno | ||
|
||
config ConfigV5Beta | ||
} | ||
|
||
func (s *SpecV5Beta) BuildMessage(ctx context.Context, _ bool, _ *ton.BlockIDExt, messages []*Message) (_ *cell.Cell, err error) { | ||
// TODO: remove block, now it is here for backwards compatibility | ||
|
||
if len(messages) > 255 { | ||
return nil, errors.New("for this type of wallet max 4 messages can be sent in the same time") | ||
} | ||
|
||
seq, err := s.seqnoFetcher(ctx, s.wallet.subwallet) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch seqno: %w", err) | ||
} | ||
|
||
actions, err := packV5BetaActions(messages) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to build actions: %w", err) | ||
} | ||
|
||
payload := cell.BeginCell(). | ||
MustStoreUInt(0x7369676e, 32). // external sign op code | ||
MustStoreInt(int64(s.config.NetworkGlobalID), 32). | ||
MustStoreInt(int64(s.config.Workchain), 8). | ||
MustStoreUInt(0, 8). // version of v5 | ||
MustStoreUInt(uint64(s.wallet.subwallet), 32). | ||
MustStoreUInt(uint64(timeNow().Add(time.Duration(s.messagesTTL)*time.Second).UTC().Unix()), 32). | ||
MustStoreUInt(uint64(seq), 32). | ||
MustStoreBuilder(actions) | ||
|
||
sign := payload.EndCell().Sign(s.wallet.key) | ||
msg := cell.BeginCell().MustStoreBuilder(payload).MustStoreSlice(sign, 512).EndCell() | ||
|
||
return msg, nil | ||
} | ||
|
||
func packV5BetaActions(messages []*Message) (*cell.Builder, error) { | ||
if len(messages) > 255 { | ||
return nil, fmt.Errorf("max 255 messages allowed for v5") | ||
} | ||
|
||
var list = cell.BeginCell().EndCell() | ||
for _, message := range messages { | ||
outMsg, err := tlb.ToCell(message.InternalMessage) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
/* | ||
out_list_empty$_ = OutList 0; | ||
out_list$_ {n:#} prev:^(OutList n) action:OutAction | ||
= OutList (n + 1); | ||
action_send_msg#0ec3c86d mode:(## 8) | ||
out_msg:^(MessageRelaxed Any) = OutAction; | ||
*/ | ||
msg := cell.BeginCell().MustStoreUInt(0x0ec3c86d, 32). | ||
MustStoreUInt(uint64(message.Mode), 8). | ||
MustStoreRef(outMsg) | ||
|
||
list = cell.BeginCell().MustStoreRef(list).MustStoreBuilder(msg).EndCell() | ||
} | ||
|
||
return cell.BeginCell().MustStoreUInt(0, 1).MustStoreRef(list), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep name V5R1, and instead of Final call it V5R2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The official name will be V5R1, and the previous W5 is V5 Beta. It is worth keeping V5R1 to avoid confusing new users of the library and to communicate that the previous version of V5 will be V5 Beta. A smaller number of users used the Beta contract, who will use the library in the future.