Skip to content
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

Add in effects that weren't being returned by Horizon #368

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 53 additions & 20 deletions services/horizon/internal/resource/effects/main.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package effects

import (
"golang.org/x/net/context"

"github.com/stellar/go/services/horizon/internal/db2/history"
"github.com/stellar/go/services/horizon/internal/render/hal"
"github.com/stellar/go/services/horizon/internal/resource/base"
"golang.org/x/net/context"
"github.com/stellar/go/support/errors"
)

var TypeNames = map[history.EffectType]string{
Expand Down Expand Up @@ -35,11 +37,7 @@ var TypeNames = map[history.EffectType]string{

// New creates a new effect resource from the provided database representation
// of the effect.
func New(
ctx context.Context,
row history.Effect,
) (result hal.Pageable, err error) {

func New(ctx context.Context, row history.Effect) (result hal.Pageable, err error) {
basev := Base{}
basev.Populate(ctx, row)

Expand Down Expand Up @@ -68,6 +66,10 @@ func New(
e := AccountFlagsUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectAccountInflationDestinationUpdated:
e := AccountInflationDestinationUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectSignerCreated:
e := SignerCreated{Base: basev}
err = row.UnmarshalDetails(&e)
Expand Down Expand Up @@ -104,21 +106,32 @@ func New(
e := Trade{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectDataCreated:
e := DataCreated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectDataRemoved:
e := DataRemoved{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
case history.EffectDataUpdated:
e := DataUpdated{Base: basev}
err = row.UnmarshalDetails(&e)
result = e
default:
result = basev
}

if err != nil {
return
return nil, errors.Wrap(err, "error unmarshaling details into effect")
}

rh, ok := result.(base.Rehydratable)

if ok {
err = rh.Rehydrate()
if rh, ok := result.(base.Rehydratable); ok {
if err := rh.Rehydrate(); err != nil {
return nil, errors.Wrap(err, "error rehydrating effect")
}
}

return
return result, nil
}

// Base provides the common structure for any effect resource effect.
Expand Down Expand Up @@ -169,6 +182,12 @@ type AccountFlagsUpdated struct {
Base
AuthRequired *bool `json:"auth_required_flag,omitempty"`
AuthRevokable *bool `json:"auth_revokable_flag,omitempty"`
AuthImmutable *bool `json:"auth_immutable_flag,omitempty"`
}

type AccountInflationDestinationUpdated struct {
Base
InflationDestination string `json:"inflation_destination"`
}

type SignerCreated struct {
Expand All @@ -180,7 +199,6 @@ type SignerCreated struct {

type SignerRemoved struct {
Base
Weight int32 `json:"weight"`
PublicKey string `json:"public_key"`
Key string `json:"key"`
}
Expand Down Expand Up @@ -212,16 +230,14 @@ type TrustlineUpdated struct {

type TrustlineAuthorized struct {
Base
Trustor string `json:"trustor"`
AssetType string `json:"asset_type"`
AssetCode string `json:"asset_code,omitempty"`
base.Asset
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a refactoring; It changes the API, please revert it.

If you'll notice, these effects don't have asset_issuer fields. By embedding the base.Asset you will be including that field.

Trustor string `json:"trustor"`
}

type TrustlineDeauthorized struct {
Base
Trustor string `json:"trustor"`
AssetType string `json:"asset_type"`
AssetCode string `json:"asset_code,omitempty"`
base.Asset
Trustor string `json:"trustor"`
}

type Trade struct {
Expand All @@ -238,6 +254,23 @@ type Trade struct {
BoughtAssetIssuer string `json:"bought_asset_issuer,omitempty"`
}

type DataCreated struct {
Base
Name string `json:"name"`
Value string `json:"value"`
}

type DataRemoved struct {
Base
Name string `json:"name"`
}

type DataUpdated struct {
Base
Name string `json:"name"`
Value string `json:"value"`
}

// interface implementations
var _ base.Rehydratable = &SignerCreated{}
var _ base.Rehydratable = &SignerRemoved{}
Expand Down