Skip to content

Commit

Permalink
Fix: generated contract code
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Jan 19, 2022
1 parent 873efb5 commit 86da0ac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 32 deletions.
6 changes: 3 additions & 3 deletions internal/chain/tezos/atomex_tez/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func New(baseURL string) *Atomextez {
return &Atomextez {
tzktAPI: api.New(baseURL),
tzktEvents: events.NewTzKT(fmt.Sprintf("%s/v1/events", baseURL)),
address: "KT1GyzWoSh9A2ACr1wQpBoGHiDrjT4oHJT2J",
address: "KT1BpYoX7rGtEJp2gvtdLWGsfb3UriymcnHN",
add: make(chan AddTx, 1024),
initiate: make(chan InitiateTx, 1024),
redeem: make(chan RedeemTx, 1024),
Expand Down Expand Up @@ -364,7 +364,7 @@ func getTransactions(ctx context.Context, tzktAPI *api.API, entrypoint, contract
})
}

// GetStorage - get `KT1GyzWoSh9A2ACr1wQpBoGHiDrjT4oHJT2J` current storage
// GetStorage - get `KT1BpYoX7rGtEJp2gvtdLWGsfb3UriymcnHN` current storage
func (contract *Atomextez) GetStorage(ctx context.Context) (Storage, error) {
var storage Storage
err := contract.tzktAPI.GetContractStorage(ctx, contract.address, &storage)
Expand All @@ -377,7 +377,7 @@ func (contract *Atomextez) BuildAddParameters(ctx context.Context, params Add) (
}

// BuildInitiateParameters - build `initiate` parameters
func (contract *Atomextez) BuildInitiateParameters(ctx context.Context, params InitiateParameters) ([]byte, error) {
func (contract *Atomextez) BuildInitiateParameters(ctx context.Context, params Initiate) ([]byte, error) {
return contract.tzktAPI.BuildContractParameters(ctx, contract.address, "initiate", params)
}

Expand Down
39 changes: 15 additions & 24 deletions internal/chain/tezos/atomex_tez/contract_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ import (

// Initiate
type Initiate struct {
Participant tezgen.Address `json:"participant" validate:"string"`
HashedSecret tezgen.Bytes `json:"hashed_secret" validate:"string"`
RefundTime tezgen.Timestamp `json:"refund_time" validate:"string"`
Payoff tezgen.Int `json:"payoff" validate:"string"`
Settings Settings `json:"settings" validate:"string"`
Participant tezgen.Address `json:"participant" validate:"string"`
}


// Initiate
type InitiateParameters struct {
Participant tezgen.Address `json:"participant" validate:"string"`
Settings Settings `json:"settings"`
}

// Settings -
// Settings
type Settings struct {
HashedSecret tezgen.Bytes `json:"hashed_secret" validate:"string"`
RefundTime tezgen.Timestamp `json:"refund_time" validate:"string"`
Payoff tezgen.Int `json:"payoff" validate:"string"`
HashedSecret tezgen.Bytes `json:"hashed_secret" validate:"string"`
}

// Add
Expand All @@ -42,21 +33,21 @@ type KeyBigMap tezgen.Bytes

// ValueBigMap
type ValueBigMap struct {
Recepients Recepients `json:"recepients"`
Settings SettingsValueBigMap `json:"settings"`
Recipients Recipients `json:"recipients" validate:"string"`
Settings Settings1 `json:"settings" validate:"string"`
}

// Recepients
type Recepients struct {
Initiator tezgen.Address `json:"initiator" validate:"string"`
Participant tezgen.Address `json:"participant" validate:"string"`
// Recipients
type Recipients struct {
Participant tezgen.Address `json:"participant" validate:"string"`
Initiator tezgen.Address `json:"initiator" validate:"string"`
}

// Settings -
type SettingsValueBigMap struct {
Amount tezgen.Int `json:"amount" validate:"string"`
RefundTime tezgen.Timestamp `json:"refund_time" validate:"string"`
Payoff tezgen.Int `json:"payoff" validate:"string"`
// Settings1
type Settings1 struct {
Amount tezgen.Int `json:"amount" validate:"string"`
RefundTime tezgen.Timestamp `json:"refund_time" validate:"string"`
Payoff tezgen.Int `json:"payoff" validate:"string"`
}

// BigMap
Expand Down
10 changes: 5 additions & 5 deletions internal/chain/tezos/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (t *Tezos) Initiate(ctx context.Context, args chain.InitiateArgs) error {
case t.cfg.Contract:
tx.Amount = args.Amount.String()

value, err = t.tezContract.BuildInitiateParameters(ctx, atomextez.InitiateParameters{
value, err = t.tezContract.BuildInitiateParameters(ctx, atomextez.Initiate{
Participant: tezgen.Address(args.Participant),
Settings: atomextez.Settings{
HashedSecret: tezgen.Bytes(hashed),
Expand Down Expand Up @@ -520,8 +520,8 @@ func (t *Tezos) parseTezosContractUpdate(ctx context.Context, update atomextez.B
Chain: chain.ChainTypeTezos,
ContractAddress: update.Contract,
BlockNumber: uint64(update.Level),
Initiator: string(update.BigMap.Value.Recepients.Initiator),
Participant: string(update.BigMap.Value.Recepients.Participant),
Initiator: string(update.BigMap.Value.Recipients.Initiator),
Participant: string(update.BigMap.Value.Recipients.Participant),
RefundTime: update.BigMap.Value.Settings.RefundTime.Value(),
Amount: decimal.NewFromBigInt(update.BigMap.Value.Settings.Amount.Int, 0),
}
Expand Down Expand Up @@ -670,8 +670,8 @@ func (t *Tezos) parseContractValueKeys(key api.BigMapKey, contract string) error
Chain: chain.ChainTypeTezos,
ContractAddress: contract,
BlockNumber: uint64(key.FirstLevel),
Initiator: string(value.Recepients.Initiator),
Participant: string(value.Recepients.Participant),
Initiator: string(value.Recipients.Initiator),
Participant: string(value.Recipients.Participant),
RefundTime: value.Settings.RefundTime.Value(),
Amount: decimal.NewFromBigInt(value.Settings.Amount.Int, 0),
}
Expand Down

0 comments on commit 86da0ac

Please sign in to comment.