Skip to content

Commit

Permalink
cli: properly support off-chain generation from cpm.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
ixje committed Sep 19, 2023
1 parent d180fc3 commit e6567c7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 16 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type SdkDestination struct {
Golang *string `yaml:"go,omitempty"`
Java *string `yaml:"java,omitempty"`
Python *string `yaml:"python,omitempty"`
TS *string `yaml:"ts,omitempty"`
}

type CPMConfig struct {
Expand Down Expand Up @@ -121,8 +122,16 @@ func (c *CPMConfig) getHosts(networkLabel string) []string {
}

func (c *CPMConfig) getSdkDestination(forLanguage string) string {
if c.Defaults.OnChain == nil {
return generators.OutputRoot + forLanguage + "/"
// TODO: this is a bit of a hack
// Resolve this properly once we have a second language that can do off-chain generation or a language that supports both
if forLanguage == LANG_TYPESCRIPT {
if c.Defaults.OffChain == nil {
return generators.OutputRoot + forLanguage + "/"
}
} else {
if c.Defaults.OnChain == nil {
return generators.OutputRoot + forLanguage + "/"
}
}

defaultLocation := generators.OutputRoot + forLanguage + "/"
Expand All @@ -147,6 +156,11 @@ func (c *CPMConfig) getSdkDestination(forLanguage string) string {
return EnsureSuffix(*path)
}
return defaultLocation
case LANG_TYPESCRIPT:
if path := c.Defaults.OffChain.SdkDestinations.TS; path != nil {
return EnsureSuffix(*path)
}
return defaultLocation
default:
return defaultLocation
}
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ It has 4 major sections which will be described in detail later on

# tools
Currently `neo-express` is the only tool that supports downloading contracts. An [issue](https://github.com/nspcc-dev/neo-go/issues/2406) exists for `neo-go` to add download support.
For SDK generation `C#`, `Java`, `Golang` and `Python` are supported.
For on-chain SDK generation `C#`, `Java`, `Golang` and `Python` are supported. For off-chain SDK generation `ts` is supported.

Each tool must specify the following 2 keys
* `canGenerateSDK` - indicates if the tool can be used for generating SDKs. Must be a bool value.
Expand Down
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,13 @@ func fetchManifestAndGenerateSDK(c *ContractConfig, host string) error {
if c.OnChain != nil {
languages = c.OnChain.Languages
}

if c.OffChain != nil {
languages = append(languages, c.OffChain.Languages...)
} else {
languages = append(languages, cfg.Defaults.OffChain.Languages...)
}

for _, l := range languages {
err = generateSDK(m, c.ScriptHash, l, cfg.getSdkDestination(l))
if err != nil {
Expand Down

0 comments on commit e6567c7

Please sign in to comment.