Skip to content

Commit

Permalink
dns renew
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-tron committed Nov 16, 2023
1 parent afd431c commit e58a526
Show file tree
Hide file tree
Showing 21 changed files with 857 additions and 98 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ translate:

install_i18n:
git clone https://github.com/mr-tron/go-i18n/
cd go-i18n/v2 && go build -o $GOPATH/bin/goi18n github.com/nicksnyder/go-i18n/v2/goi18n
cd go-i18n/v2 && go build -o $$GOPATH/bin/goi18n github.com/nicksnyder/go-i18n/v2/goi18n ; cd ../.. ; rm -rf go-i18n
run:
go run cmd/api/main.go

Expand Down
25 changes: 25 additions & 0 deletions api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@
"DepositStake": {
"$ref": "#/components/schemas/DepositStakeAction"
},
"DomainRenew": {
"$ref": "#/components/schemas/DomainRenewAction"
},
"ElectionsDepositStake": {
"$ref": "#/components/schemas/ElectionsDepositStakeAction"
},
Expand Down Expand Up @@ -971,6 +974,7 @@
"SmartContractExec",
"ElectionsRecoverStake",
"ElectionsDepositStake",
"DomainRenew",
"Unknown"
],
"example": "TonTransfer",
Expand Down Expand Up @@ -2524,6 +2528,27 @@
],
"type": "object"
},
"DomainRenewAction": {
"properties": {
"contract_address": {
"example": "0:da6b1b6663a0e4d18cc8574ccd9db5296e367dd9324706f3bbd9eb1cd2caf0bf",
"type": "string"
},
"domain": {
"example": "vasya.ton",
"type": "string"
},
"renewer": {
"$ref": "#/components/schemas/AccountAddress"
}
},
"required": [
"domain",
"contract_address",
"renewer"
],
"type": "object"
},
"ElectionsDepositStakeAction": {
"properties": {
"amount": {
Expand Down
18 changes: 18 additions & 0 deletions api/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4536,6 +4536,7 @@ components:
- SmartContractExec
- ElectionsRecoverStake
- ElectionsDepositStake
- DomainRenew
- Unknown
status:
type: string
Expand Down Expand Up @@ -4577,6 +4578,8 @@ components:
$ref: '#/components/schemas/JettonSwapAction'
SmartContractExec:
$ref: '#/components/schemas/SmartContractAction'
DomainRenew:
$ref: '#/components/schemas/DomainRenewAction'
simple_preview:
$ref: '#/components/schemas/ActionSimplePreview'
TonTransferAction:
Expand Down Expand Up @@ -4626,6 +4629,21 @@ components:
type: string
refund:
$ref: '#/components/schemas/Refund'
DomainRenewAction:
type: object
required:
- domain
- contract_address
- renewer
properties:
domain:
type: string
example: "vasya.ton"
contract_address:
type: string
example: "0:da6b1b6663a0e4d18cc8574ccd9db5296e367dd9324706f3bbd9eb1cd2caf0bf"
renewer:
$ref: '#/components/schemas/AccountAddress'
NftItemTransferAction:
type: object
required:
Expand Down
2 changes: 1 addition & 1 deletion examples/golang/sse/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tonkeeper/opentonapi/examples/golang/sse

go 1.21.3
go 1.21

require github.com/tonkeeper/opentonapi/tonapi v0.0.0-20231101195704-1c8ad29379ba

Expand Down
2 changes: 1 addition & 1 deletion examples/golang/tonapi-sdk/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tonkeeper/opentonapi/examples/tonapi-sdk

go 1.21.3
go 1.21

require github.com/tonkeeper/opentonapi/tonapi v0.0.0-20231101195704-1c8ad29379ba

Expand Down
2 changes: 1 addition & 1 deletion examples/golang/websocket/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tonkeeper/opentonapi/examples/golang/websocket

go 1.21.3
go 1.21

require github.com/tonkeeper/opentonapi/tonapi v0.0.0-20231101195704-1c8ad29379ba

Expand Down
30 changes: 30 additions & 0 deletions pkg/api/event_converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,33 @@ func (h *Handler) convertWithdrawStake(d *bath.WithdrawStakeAction, acceptLangua
return action, simplePreview
}

func (h *Handler) convertDomainRenew(ctx context.Context, d *bath.DnsRenewAction, acceptLanguage string, viewer *tongo.AccountID) (oas.OptDomainRenewAction, oas.ActionSimplePreview) {
var action oas.OptDomainRenewAction
var domain = "unknown"
nfts, err := h.storage.GetNFTs(ctx, []ton.AccountID{d.Item})
if err == nil && len(nfts) == 1 && nfts[0].DNS != nil {
domain = *nfts[0].DNS
}
action.SetTo(oas.DomainRenewAction{
Domain: domain,
ContractAddress: d.Item.String(),
Renewer: convertAccountAddress(d.Renewer, h.addressBook),
})
simplePreview := oas.ActionSimplePreview{
Name: "Domain Renew",
Description: i18n.T(acceptLanguage, i18n.C{
DefaultMessage: &i18n.M{
ID: "domainRenewAction",
Other: "Renew domain {{.Value}}",
},
TemplateData: i18n.Template{"Value": domain},
}),
Accounts: distinctAccounts(viewer, h.addressBook, &d.Renewer, &d.Item),
Value: oas.NewOptString(domain),
}
return action, simplePreview
}

func (h *Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a bath.Action, acceptLanguage oas.OptString) (oas.Action, bool, error) {
action := oas.Action{
Type: oas.ActionType(a.Type),
Expand Down Expand Up @@ -657,6 +684,9 @@ func (h *Handler) convertAction(ctx context.Context, viewer *tongo.AccountID, a
action.WithdrawStakeRequest, action.SimplePreview = h.convertWithdrawStakeRequest(a.WithdrawStakeRequest, acceptLanguage.Value, viewer)
case bath.WithdrawStake:
action.WithdrawStake, action.SimplePreview = h.convertWithdrawStake(a.WithdrawStake, acceptLanguage.Value, viewer)
case bath.DnsRenew:
action.DomainRenew, action.SimplePreview = h.convertDomainRenew(ctx, a.DnsRenew, acceptLanguage.Value, viewer)

}
return action, spamDetected, nil
}
Expand Down
1 change: 1 addition & 0 deletions pkg/api/i18n/translations/active.en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ helloWorld = "Hello world!"
auctionBidMessage = "Bidding {{.Amount}} for {{.NftName}}"
contractDeployAction = "Deploying a contract{{ if .Interfaces }} with interfaces {{.Interfaces}}{{ end }}"
depositStakeAction = "Deposit {{.Value}} to staking pool"
domainRenewAction = "Renew domain {{.Value}}"
electionsDepositStakeAction = "Depositing {{.Amount}} for stake"
electionsRecoverStakeAction = "Recover {{.Amount}} stake"
jettonBurnAction = "Burning {{.Value}} {{.JettonName}}"
Expand Down
5 changes: 4 additions & 1 deletion pkg/bath/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
WithdrawStakeRequest ActionType = "WithdrawStakeRequest"
JettonSwap ActionType = "JettonSwap"
AuctionBid ActionType = "AuctionBid"
DnsRenew ActionType = "DnsRenew"

RefundDnsTg RefundType = "DNS.tg"
RefundDnsTon RefundType = "DNS.ton"
Expand Down Expand Up @@ -76,6 +77,7 @@ type (
WithdrawStake *WithdrawStakeAction `json:",omitempty"`
WithdrawStakeRequest *WithdrawStakeRequestAction `json:",omitempty"`
JettonSwap *JettonSwapAction `json:",omitempty"`
DnsRenew *DnsRenewAction `json:",omitempty"`
Success bool
Type ActionType
}
Expand Down Expand Up @@ -245,7 +247,7 @@ func (a Action) ContributeToExtra(account tongo.AccountID) int64 {
return 0
}
switch a.Type {
case NftItemTransfer, ContractDeploy, UnSubscription, JettonMint, JettonBurn, WithdrawStakeRequest: // actions without extra
case NftItemTransfer, ContractDeploy, UnSubscription, JettonMint, JettonBurn, WithdrawStakeRequest, DnsRenew: // actions without extra
return 0
case TonTransfer:
return detectDirection(account, a.TonTransfer.Sender, a.TonTransfer.Recipient, a.TonTransfer.Amount)
Expand Down Expand Up @@ -309,6 +311,7 @@ func (a Action) IsSubject(account tongo.AccountID) bool {
a.JettonSwap,
a.JettonMint,
a.JettonBurn,
a.DnsRenew,
} {
if i != nil && !reflect.ValueOf(i).IsNil() {
return slices.Contains(i.SubjectAccounts(), account)
Expand Down
5 changes: 5 additions & 0 deletions pkg/bath/bath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ func TestFindActions(t *testing.T) {
hash: "08013737ecc5796d635f5c439d6d6913b4e894a8cdd86fd329c09bc51ea55239",
filenamePrefix: "telemint-deploy",
},
{
name: "domain renew",
hash: "bcc48fcebc9635febcd1834ef40e1afab71c3ab46dd81ddf1d267474dae13923",
filenamePrefix: "domain-renew",
},
} {
t.Run(c.name, func(t *testing.T) {
trace, err := storage.GetTrace(context.Background(), tongo.MustParseHash(c.hash))
Expand Down
41 changes: 41 additions & 0 deletions pkg/bath/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package bath

import (
"github.com/tonkeeper/tongo/abi"
"github.com/tonkeeper/tongo/tlb"
"github.com/tonkeeper/tongo/ton"
)

type BubbleDnsItemRenew struct {
DnsRenewAction
Success bool
}

type DnsRenewAction struct {
Item ton.AccountID
Renewer ton.AccountID
}

func (b BubbleDnsItemRenew) ToAction() *Action {
return &Action{Success: b.Success, Type: DnsRenew, DnsRenew: &b.DnsRenewAction}
}

func (a DnsRenewAction) SubjectAccounts() []ton.AccountID {
return []ton.AccountID{a.Renewer, a.Item}
}

var DNSRenewStraw = Straw[BubbleDnsItemRenew]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.DeleteDnsRecordMsgOp), HasInterface(abi.NftItem), func(bubble *Bubble) bool {
return bubble.Info.(BubbleTx).decodedBody.Value.(abi.DeleteDnsRecordMsgBody).Key.Equal(tlb.Bits256{})
}},
Builder: func(newAction *BubbleDnsItemRenew, bubble *Bubble) error {
tx := bubble.Info.(BubbleTx)
newAction.Renewer = tx.inputFrom.Address
newAction.Item = tx.account.Address
return nil
},
SingleChild: &Straw[BubbleDnsItemRenew]{
Optional: true,
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.BounceMsgOp)},
},
}
109 changes: 109 additions & 0 deletions pkg/bath/nft.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package bath

import (
"fmt"
"github.com/tonkeeper/opentonapi/internal/g"
"github.com/tonkeeper/tongo/abi"
)

var NftTransferNotifyStraw = Straw[BubbleNftTransfer]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.NftOwnershipAssignedMsgOp)},
Builder: func(newAction *BubbleNftTransfer, bubble *Bubble) error {
receiverTx := bubble.Info.(BubbleTx)
transfer := receiverTx.decodedBody.Value.(abi.NftOwnershipAssignedMsgBody)
newAction.success = true
if receiverTx.inputFrom == nil {
return fmt.Errorf("nft transfer notify without sender")
}
newAction.account = *receiverTx.inputFrom
if newAction.sender == nil {
newAction.sender = parseAccount(transfer.PrevOwner)
}
newAction.recipient = &receiverTx.account
newAction.payload = transfer.ForwardPayload.Value
return nil
},
}

var NftTransferStraw = Straw[BubbleNftTransfer]{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.NftTransferMsgOp)},
Builder: func(newAction *BubbleNftTransfer, bubble *Bubble) error {
tx := bubble.Info.(BubbleTx)
transfer := tx.decodedBody.Value.(abi.NftTransferMsgBody)
newAction.account = tx.account
newAction.success = tx.success
newAction.sender = tx.inputFrom
newAction.payload = transfer.ForwardPayload.Value
if newAction.recipient == nil {
newAction.recipient = parseAccount(transfer.NewOwner)
}
return nil
},
Children: []Straw[BubbleNftTransfer]{
Optional(NftTransferNotifyStraw),
{
CheckFuncs: []bubbleCheck{IsTx, HasOperation(abi.ExcessMsgOp)},
Optional: true,
},
},
}

type BubbleNftTransfer struct {
success bool
account Account
sender *Account
recipient *Account
payload abi.NFTPayload
}

func (b BubbleNftTransfer) ToAction() (action *Action) {
a := Action{
NftItemTransfer: &NftTransferAction{
Recipient: b.recipient.Addr(),
Sender: b.sender.Addr(),
Nft: b.account.Address,
},
Success: b.success,
Type: NftItemTransfer,
}
switch b.payload.SumType {
case abi.TextCommentNFTOp:
a.NftItemTransfer.Comment = g.Pointer(string(b.payload.Value.(abi.TextCommentNFTPayload).Text))
case abi.EncryptedTextCommentNFTOp:
a.NftItemTransfer.EncryptedComment = &EncryptedComment{
CipherText: b.payload.Value.(abi.EncryptedTextCommentNFTPayload).CipherText,
EncryptionType: "simple",
}
case abi.EmptyNFTOp:
default:
if b.payload.SumType != abi.UnknownNFTOp {
a.NftItemTransfer.Comment = g.Pointer("Call: " + b.payload.SumType)
} else if b.recipient != nil && b.recipient.Is(abi.Wallet) {
// we don't want to show the scary "Call: Ugly HEX" to the wallet contract
} else if b.payload.OpCode != nil {
a.NftItemTransfer.Comment = g.Pointer(fmt.Sprintf("Call: 0x%08x", *b.payload.OpCode))
}
}
return &a
}

//type BubbleNftMint struct {
// Minter *ton.AccountID
// Owner *ton.AccountID
// Item ton.AccountID
//}
//
//func (b BubbleNftMint) ToAction() *Action {
// //TODO implement me
// panic("implement me")
//}
//
//var NFTMintStraw = Straw[BubbleNftMint]{
//
// Children: []Straw[BubbleNftMint]{
// {
//
// },
// },
// CheckFuncs: []bubbleCheck{Is(BubbleContractDeploy{})},
//}
Loading

0 comments on commit e58a526

Please sign in to comment.