Skip to content

Commit

Permalink
feat: move migrations into dedicated module
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Aug 6, 2024
1 parent 24b6f67 commit 25b4a3e
Show file tree
Hide file tree
Showing 15 changed files with 1,070 additions and 228 deletions.
18 changes: 0 additions & 18 deletions go/node/audit/v1/migrate/v1beta3.go

This file was deleted.

37 changes: 0 additions & 37 deletions go/node/deployment/v1/migrate/v1beta3.go

This file was deleted.

45 changes: 0 additions & 45 deletions go/node/deployment/v1beta4/migrate/v1beta3.go

This file was deleted.

46 changes: 0 additions & 46 deletions go/node/market/v1/migrate/v1beta4.go

This file was deleted.

39 changes: 0 additions & 39 deletions go/node/market/v1beta5/migrate/v1beta4.go

This file was deleted.

25 changes: 25 additions & 0 deletions go/node/migrate/audit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package migrate

import (
"github.com/akash-network/akash-api/go/node/audit/v1beta3"
"github.com/cosmos/cosmos-sdk/codec"

v1 "pkg.akt.dev/go/node/audit/v1"
)

func AuditedAttributesV1beta3Prefix() []byte {
return v1beta3.PrefixProviderID()
}

func AuditedAttributesFromV1beta3(cdc codec.BinaryCodec, fromBz []byte) v1.Provider {
var from v1beta3.AuditedAttributes
cdc.MustUnmarshal(fromBz, &from)

to := v1.Provider{
Owner: from.Owner,
Auditor: from.Auditor,
Attributes: AttributesFromV1Beta3(from.Attributes),
}

return to
}
10 changes: 9 additions & 1 deletion go/node/cert/v1/migrate/v1beta3.go → go/node/migrate/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ package migrate

import (
"github.com/akash-network/akash-api/go/node/cert/v1beta3"
"github.com/cosmos/cosmos-sdk/codec"

v1 "pkg.akt.dev/go/node/cert/v1"
)

func CertFromV1beta3(from v1beta3.Certificate) v1.Certificate {
func CertV1beta3Prefix() []byte {
return v1beta3.PrefixCertificateID()
}

func CertFromV1beta3(cdc codec.BinaryCodec, fromBz []byte) v1.Certificate {
var from v1beta3.Certificate
cdc.MustUnmarshal(fromBz, &from)

to := v1.Certificate{
State: v1.State(from.State),
Cert: make([]byte, len(from.Cert)),
Expand Down
94 changes: 94 additions & 0 deletions go/node/migrate/deployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package migrate

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/gogoproto/proto"

"github.com/akash-network/akash-api/go/node/deployment/v1beta3"
v1 "pkg.akt.dev/go/node/deployment/v1"
"pkg.akt.dev/go/node/deployment/v1beta4"
)

func init() {
proto.RegisterType((*v1beta3.DepositDeploymentAuthorization)(nil), "akash.deployment.v1beta3.DepositDeploymentAuthorization")
}


func DeploymentV1beta3Prefix() []byte {
return v1beta3.DeploymentPrefix()
}

func GroupV1beta3Prefix() []byte {
return v1beta3.GroupPrefix()
}

func DeploymentIDFromV1Beta3(from v1beta3.DeploymentID) v1.DeploymentID {
return v1.DeploymentID{
Owner: from.Owner,
DSeq: from.DSeq,
}
}

func GroupIDFromV1Beta3(from v1beta3.GroupID) v1.GroupID {
return v1.GroupID{
Owner: from.Owner,
DSeq: from.DSeq,
GSeq: from.GSeq,
}
}

func DeploymentFromV1beta3(cdc codec.BinaryCodec, fromBz []byte) v1.Deployment {
var from v1beta3.Deployment
cdc.MustUnmarshal(fromBz, &from)

return v1.Deployment{
ID: DeploymentIDFromV1Beta3(from.DeploymentID),
State: v1.Deployment_State(from.State),
Hash: from.Version,
CreatedAt: from.CreatedAt,
}
}

func DepositAuthorizationFromV1beta3(from v1beta3.DepositDeploymentAuthorization) v1.DepositAuthorization {
return v1.DepositAuthorization{
SpendLimit: from.SpendLimit,
}
}

func ResourceUnitFromV1Beta3(id uint32, from v1beta3.ResourceUnit) v1beta4.ResourceUnit {
return v1beta4.ResourceUnit{
Resources: ResourcesFromV1Beta3(id, from.Resources),
Count: from.Count,
Price: from.Price,
}
}

func ResourcesUnitsFromV1Beta3(from []v1beta3.ResourceUnit) v1beta4.ResourceUnits {
res := make(v1beta4.ResourceUnits, 0, len(from))

for i, oval := range from {
res = append(res, ResourceUnitFromV1Beta3(uint32(i+1), oval))
}

return res
}

func GroupSpecFromV1Beta3(from v1beta3.GroupSpec) v1beta4.GroupSpec {
return v1beta4.GroupSpec{
Name: from.Name,
Requirements: PlacementRequirementsFromV1Beta3(from.Requirements),
Resources: ResourcesUnitsFromV1Beta3(from.Resources),
}
}

func GroupFromV1Beta3(cdc codec.BinaryCodec, fromBz []byte) v1beta4.Group {
var from v1beta3.Group
cdc.MustUnmarshal(fromBz, &from)

return v1beta4.Group{
ID: GroupIDFromV1Beta3(from.GroupID),
State: v1beta4.Group_State(from.State),
GroupSpec: GroupSpecFromV1Beta3(from.GroupSpec),
CreatedAt: from.CreatedAt,
}
}
19 changes: 17 additions & 2 deletions go/node/escrow/v1/migrate/v1beta3.go → go/node/migrate/escrow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@ package migrate

import (
"github.com/akash-network/akash-api/go/node/escrow/v1beta3"
"github.com/cosmos/cosmos-sdk/codec"

v1 "pkg.akt.dev/go/node/escrow/v1"
)

func AccountV1beta3Prefix() []byte {
return v1beta3.AccountKeyPrefix()
}

func PaymentV1beta3Prefix() []byte {
return v1beta3.PaymentKeyPrefix()
}

func AccountIDFromV1beta3(from v1beta3.AccountID) v1.AccountID {
return v1.AccountID{
Scope: from.Scope,
XID: from.XID,
}
}

func AccountFromV1beta3(from v1beta3.Account) v1.Account {
func AccountFromV1beta3(cdc codec.BinaryCodec, fromBz []byte) v1.Account {
var from v1beta3.Account
cdc.MustUnmarshal(fromBz, &from)

to := v1.Account{
ID: AccountIDFromV1beta3(from.ID),
Owner: from.Owner,
Expand All @@ -28,7 +40,10 @@ func AccountFromV1beta3(from v1beta3.Account) v1.Account {
return to
}

func FractionalPaymentFromV1beta3(from v1beta3.FractionalPayment) v1.FractionalPayment {
func FractionalPaymentFromV1beta3(cdc codec.BinaryCodec, fromBz []byte) v1.FractionalPayment {
var from v1beta3.FractionalPayment
cdc.MustUnmarshal(fromBz, &from)

to := v1.FractionalPayment{
AccountID: AccountIDFromV1beta3(from.AccountID),
PaymentID: from.PaymentID,
Expand Down
Loading

0 comments on commit 25b4a3e

Please sign in to comment.