Skip to content

Commit 1b9ecbc

Browse files
committed
Add Array type to go-gen
1 parent efaefa0 commit 1b9ecbc

14 files changed

+37
-37
lines changed

packages/go-gen/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ mod tests {
251251
Binary []byte `json:"binary"`
252252
Checksum Checksum `json:"checksum"`
253253
HexBinary string `json:"hex_binary"`
254-
NestedBinary []*[]byte `json:"nested_binary"`
254+
NestedBinary Array[*[]byte] `json:"nested_binary"`
255255
Uint128 string `json:"uint128"`
256256
}"#,
257257
);
@@ -456,7 +456,7 @@ mod tests {
456456
code,
457457
r#"
458458
type A struct {
459-
A [][][]*B `json:"a"`
459+
A Array[Array[Array[*B]]] `json:"a"`
460460
}
461461
type B struct { }"#,
462462
);
@@ -470,7 +470,7 @@ mod tests {
470470
code,
471471
r#"
472472
type C struct {
473-
C [][][]*string `json:"c"`
473+
C Array[Array[Array[*string]]] `json:"c"`
474474
}"#,
475475
);
476476
}

packages/go-gen/src/schema.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ pub fn type_from_instance_type(
210210
// so we can pass null as elements
211211
// otherwise they would just be omitted from the array
212212
replace_custom_type(&if item_type.nullability == Nullability::Nullable {
213-
format!("[]*{}", item_type.name)
213+
format!("Array[*{}]", item_type.name)
214214
} else {
215-
format!("[]{}", item_type.name)
215+
format!("Array[{}]", item_type.name)
216216
})
217217
} else {
218218
unreachable!("instance type should be one of the above")

packages/go-gen/tests/cosmwasm_std__AllBalanceResponse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// AllBalancesResponse is the expected response to AllBalancesQuery
22
type AllBalancesResponse struct {
3-
Amount []Coin `json:"amount"` // in wasmvm, there is an alias for `[]Coin`
3+
Amount Array[Coin] `json:"amount"`
44
}
55

66
// Coin is a string representation of the sdk.Coin type (more portable than sdk.Int)

packages/go-gen/tests/cosmwasm_std__AllDelegationsResponse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// AllDelegationsResponse is the expected response to AllDelegationsQuery
22
type AllDelegationsResponse struct {
3-
Delegations []Delegation `json:"delegations"` // in wasmvm, there is an alias for `[]Delegation`
3+
Delegations Array[Delegation] `json:"delegations"`
44
}
55

66
// Coin is a string representation of the sdk.Coin type (more portable than sdk.Int)

packages/go-gen/tests/cosmwasm_std__AllValidatorsResponse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// AllValidatorsResponse is the expected response to AllValidatorsQuery
22
type AllValidatorsResponse struct {
3-
Validators []Validator `json:"validators"` // in wasmvm, there is an alias for `[]Validator`
3+
Validators Array[Validator] `json:"validators"`
44
}
55

66
type Validator struct {
@@ -11,4 +11,4 @@ type Validator struct {
1111
MaxChangeRate string `json:"max_change_rate"`
1212
// decimal string, eg "0.02"
1313
MaxCommission string `json:"max_commission"`
14-
}
14+
}

packages/go-gen/tests/cosmwasm_std__BankMsg.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// SendMsg contains instructions for a Cosmos-SDK/SendMsg
22
// It has a fixed interface here and should be converted into the proper SDK format before dispatching
33
type SendMsg struct {
4-
Amount []Coin `json:"amount"`
5-
ToAddress string `json:"to_address"`
4+
Amount Array[Coin] `json:"amount"`
5+
ToAddress string `json:"to_address"`
66
}
77

88
// BurnMsg will burn the given coins from the contract's account.
99
// There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper.
1010
// Important if a contract controls significant token supply that must be retired.
1111
type BurnMsg struct {
12-
Amount []Coin `json:"amount"`
12+
Amount Array[Coin] `json:"amount"`
1313
}
1414

1515
type BankMsg struct {

packages/go-gen/tests/cosmwasm_std__DelegationResponse.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ type Coin struct {
1010
}
1111

1212
type FullDelegation struct {
13-
AccumulatedRewards []Coin `json:"accumulated_rewards"` // in wasmvm, there is an alias for `[]Coin`
14-
Amount Coin `json:"amount"`
15-
CanRedelegate Coin `json:"can_redelegate"`
16-
Delegator string `json:"delegator"`
17-
Validator string `json:"validator"`
18-
}
13+
AccumulatedRewards Array[Coin] `json:"accumulated_rewards"`
14+
Amount Coin `json:"amount"`
15+
CanRedelegate Coin `json:"can_redelegate"`
16+
Delegator string `json:"delegator"`
17+
Validator string `json:"validator"`
18+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L169-L178>
22
type DelegationRewardsResponse struct {
3-
Rewards []DecCoin `json:"rewards"`
3+
Rewards Array[DecCoin] `json:"rewards"` // in wasmvm, this has type `[]DecCoin`
44
}
55

66
// A coin type with decimal amount. Modeled after the Cosmos SDK's [DecCoin](https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/base/v1beta1/coin.proto#L32-L41) type
77
type DecCoin struct {
88
Amount string `json:"amount"`
99
Denom string `json:"denom"`
10-
}
10+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L189-L200>
22
type DelegationTotalRewardsResponse struct {
3-
Rewards []DelegatorReward `json:"rewards"`
4-
Total []DecCoin `json:"total"`
3+
Rewards Array[DelegatorReward] `json:"rewards"` // in wasmvm, this has type `[]DelegatorReward`
4+
Total Array[DecCoin] `json:"total"` // in wasmvm, this has type `[]DecCoin`
55
}
66

77
// A coin type with decimal amount. Modeled after the Cosmos SDK's [DecCoin](https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/base/v1beta1/coin.proto#L32-L41) type
@@ -11,6 +11,6 @@ type DecCoin struct {
1111
}
1212

1313
type DelegatorReward struct {
14-
Reward []DecCoin `json:"reward"`
15-
ValidatorAddress string `json:"validator_address"`
16-
}
14+
Reward Array[DecCoin] `json:"reward"` // in wasmvm, this has type `[]DecCoin`
15+
ValidatorAddress string `json:"validator_address"`
16+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// See <https://github.com/cosmos/cosmos-sdk/blob/b0acf60e6c39f7ab023841841fc0b751a12c13ff/proto/cosmos/distribution/v1beta1/query.proto#L212-L220>
22
type DelegatorValidatorsResponse struct {
3-
Validators []string `json:"validators"`
4-
}
3+
Validators Array[string] `json:"validators"` // in wasmvm, this has type `[]string`
4+
}

0 commit comments

Comments
 (0)