Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthpun committed May 24, 2024
1 parent 12fca11 commit 56c86ac
Showing 1 changed file with 48 additions and 85 deletions.
133 changes: 48 additions & 85 deletions values.go
Original file line number Diff line number Diff line change
Expand Up @@ -2070,133 +2070,96 @@ func (v TypeValue) String() string {

// Capability

type Capability interface {
Value
isCapability()
}

// PathCapability
// Deprecated: removed in v1.0.0

type DeprecatedPathCapability struct {
BorrowType Type
Path Path
Address Address
type Capability struct {
BorrowType Type
Address Address
DeprecatedPath Path
ID UInt64
}

var _ Value = DeprecatedPathCapability{}
var _ Value = Capability{}

func NewDeprecatedPathCapability(
func NewCapability(
id UInt64,
address Address,
path Path,
borrowType Type,
) DeprecatedPathCapability {
return DeprecatedPathCapability{
Path: path,
) IDCapability {
return IDCapability{
ID: id,
Address: address,
BorrowType: borrowType,
}
}

func NewDeprecatedMeteredPathCapability(
func NewMeteredCapability(
gauge common.MemoryGauge,
id UInt64,
address Address,
path Path,
borrowType Type,
) DeprecatedPathCapability {
common.UseMemory(gauge, common.PathCapabilityValueStringMemoryUsage) // TODO: confirm if this is right
return NewDeprecatedPathCapability(
) Capability {
common.UseMemory(gauge, common.CadenceCapabilityValueMemoryUsage)
return NewCapability(
id,
address,
path,
borrowType,
)
}

func (DeprecatedPathCapability) isValue() {}
func (Capability) isValue() {}

func (DeprecatedPathCapability) isCapability() {}
func (Capability) isCapability() {}

func (v DeprecatedPathCapability) Type() Type {
func (v Capability) Type() Type {
return NewCapabilityType(v.BorrowType)
}

func (v DeprecatedPathCapability) MeteredType(gauge common.MemoryGauge) Type {
func (v Capability) MeteredType(gauge common.MemoryGauge) Type {
return NewMeteredCapabilityType(gauge, v.BorrowType)
}

func (DeprecatedPathCapability) ToGoValue() any {
return nil
}

func (v DeprecatedPathCapability) String() string {
var borrowType string
if v.BorrowType != nil {
borrowType = v.BorrowType.ID()
func (v Capability) String() string {
if v.DeprecatedPath.String() != "" {
return format.DeprecatedPathCapability(
v.BorrowType.ID(),
v.Address.String(),
v.DeprecatedPath.String(),
)
} else {
return format.Capability(
v.BorrowType.ID(),
v.Address.String(),
v.ID.String(),
)
}

return format.DeprecatedPathCapability(
borrowType,
v.Address.String(),
v.Path.String(),
)
}

// IDCapability

type IDCapability struct {
BorrowType Type
Address Address
ID UInt64
}

var _ Value = IDCapability{}

func NewCapability(
id UInt64,
// Deprecated: removed in v1.0.0
func NewDeprecatedPathCapability(
address Address,
path Path,
borrowType Type,
) IDCapability {
return IDCapability{
ID: id,
Address: address,
BorrowType: borrowType,
) Capability {
return Capability{
DeprecatedPath: path,
Address: address,
BorrowType: borrowType,
}
}

func NewMeteredCapability(
func NewDeprecatedMeteredPathCapability(
gauge common.MemoryGauge,
id UInt64,
address Address,
path Path,
borrowType Type,
) IDCapability {
common.UseMemory(gauge, common.CadenceCapabilityValueMemoryUsage)
return NewCapability(
id,
) Capability {
common.UseMemory(gauge, common.CadenceDeprecatedPathCapabilityValueMemoryUsage)
return NewDeprecatedPathCapability(
address,
path,
borrowType,
)
}

func (IDCapability) isValue() {}

func (IDCapability) isCapability() {}

func (v IDCapability) Type() Type {
return NewCapabilityType(v.BorrowType)
}

func (v IDCapability) MeteredType(gauge common.MemoryGauge) Type {
return NewMeteredCapabilityType(gauge, v.BorrowType)
}

func (v IDCapability) String() string {
return format.Capability(
v.BorrowType.ID(),
v.Address.String(),
v.ID.String(),
)
}

// Enum
type Enum struct {
EnumType *EnumType
Expand Down

0 comments on commit 56c86ac

Please sign in to comment.