-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add get_subscriptions endpoint + fix config parsing * Fix initial config * Add wonkydict to account for default empty values of either [] or {} * Add get_owned_stores endpoint * Add get_mirrors endpoint * Add delete_mirror * Datalayer add_mirror endpoint * Add unsubscribe endpoint * Return a better error when wonkyset can't be unmarshalled * Update pkg/types/wonkyset_test.go Co-authored-by: Patrick Maslana <79757486+pmaslana@users.noreply.github.com> * Update pkg/types/wonkyset.go Co-authored-by: Starttoaster <b.butler@chia.net> --------- Co-authored-by: Patrick Maslana <79757486+pmaslana@users.noreply.github.com> Co-authored-by: Starttoaster <b.butler@chia.net>
- Loading branch information
1 parent
f278718
commit ac5fb4a
Showing
6 changed files
with
266 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/samber/mo" | ||
) | ||
|
||
// DatalayerMirror represents a single mirror for a data store | ||
type DatalayerMirror struct { | ||
CoinID Bytes32 `json:"coin_id"` | ||
LauncherID Bytes32 `json:"launcher_id"` | ||
Amount uint64 `json:"amount"` | ||
URLs []string `json:"urls"` | ||
Ours bool `json:"ours"` | ||
ConfirmedAtHeight mo.Option[uint32] `json:"confirmed_at_height"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// WonkySet is just an alias for map[string]string that will unmarshal correctly from the empty forms {} and [] | ||
// In chia-blockchain, the default for some sets was incorrectly [] in the initial config | ||
// so this ensures compatability with both ways the empty values could show up | ||
type WonkySet map[string]string | ||
|
||
// UnmarshalYAML implements the yaml.Unmarshaler interface. | ||
func (ws *WonkySet) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
// Attempt to unmarshal into a slice of strings. | ||
var sliceErr error | ||
var mapErr error | ||
var slice []string | ||
if sliceErr = unmarshal(&slice); sliceErr == nil { | ||
*ws = make(map[string]string) | ||
return nil | ||
} | ||
|
||
// Attempt to unmarshal into a map. | ||
var m map[string]string | ||
if mapErr = unmarshal(&m); mapErr != nil { | ||
return fmt.Errorf("failed to unmarshal as either string slice or map: slice err: %s | map err: %s", sliceErr.Error(), mapErr.Error()) | ||
} | ||
|
||
*ws = m | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package types_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v3" | ||
|
||
"github.com/chia-network/go-chia-libs/pkg/config" | ||
) | ||
|
||
// TestWonkySet_UnmarshalYAML ensures that this will unmarshal both empty list [] and dict {} into empty map[string]string | ||
// And also ensures an actual !!set as it would show up in the yaml unmarshals correctly | ||
func TestWonkySet_UnmarshalYAML(t *testing.T) { | ||
var yamlWithList = []byte(` | ||
farmer: | ||
pool_public_keys: [] | ||
`) | ||
var yamlWithDict = []byte(` | ||
farmer: | ||
pool_public_keys: {} | ||
`) | ||
|
||
var yamlWithData = []byte(` | ||
farmer: | ||
pool_public_keys: !!set | ||
abc123: null | ||
456xyz: null | ||
`) | ||
|
||
cfg := &config.ChiaConfig{} | ||
err := yaml.Unmarshal(yamlWithList, cfg) | ||
assert.NoError(t, err) | ||
assert.Len(t, cfg.Farmer.PoolPublicKeys, 0) | ||
|
||
cfg = &config.ChiaConfig{} | ||
err = yaml.Unmarshal(yamlWithDict, cfg) | ||
assert.NoError(t, err) | ||
assert.Len(t, cfg.Farmer.PoolPublicKeys, 0) | ||
|
||
cfg = &config.ChiaConfig{} | ||
err = yaml.Unmarshal(yamlWithData, cfg) | ||
assert.NoError(t, err) | ||
assert.Len(t, cfg.Farmer.PoolPublicKeys, 2) | ||
} |