Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ xdr/Stellar-exporter.x


XDRGEN_COMMIT=b423e1da9504239fb3136cbcc5f9beeb37795837
# Bumped to stellar-xdr@8521b97 for Protocol 28 (CAP-0083).
XDR_COMMIT=8521b97ba0e8e71d746bf3bd73def92110e6a21f
# Bumped to stellar-xdr@787382e for Protocol 28 (CAP-0084).
XDR_COMMIT=787382ef2099cca168ca1cb282730d6b7b9e2f16

.PHONY: xdr xdr-clean xdr-update

Expand Down Expand Up @@ -68,7 +68,7 @@ xdr/xdr_generated.go: $(XDRS)

# Optional comma-separated features for #ifdef resolution in the XDR files.
# Empty = no features enabled; only unconditional definitions are emitted.
XDR_FEATURES ?= CAP_0083
XDR_FEATURES ?= CAP_0083,CAP_0084_MUXED_CONTRACT

# Generates xdr/xdr_views_generated.go via a two-step pipeline:
# 1. The rust `generator-definitions-json` tool parses the .x files and
Expand Down
50 changes: 49 additions & 1 deletion gxdr/xdr_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions processors/token_transfer/helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package token_transfer

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/stellar/go-stellar-sdk/strkey"
"github.com/stellar/go-stellar-sdk/xdr"
)

// TestExtractAddressMuxedContract verifies that CAP-0084 muxed contract
// destinations are parsed without panicking and yield the underlying base
// contract address. The muxed id is not surfaced here; that is deferred to
// horizon's processor.
func TestExtractAddressMuxedContract(t *testing.T) {
contractID := xdr.ContractId([32]byte{1})
val := xdr.ScVal{
Type: xdr.ScValTypeScvAddress,
Address: &xdr.ScAddress{
Type: xdr.ScAddressTypeScAddressTypeMuxedContract,
MuxedContract: &xdr.MuxedContract{
Id: 99,
ContractId: contractID,
},
},
}

got, err := extractAddress(val)
require.NoError(t, err)
require.Equal(t, strkey.MustEncode(strkey.VersionByteContract, contractID[:]), got)
}
10 changes: 10 additions & 0 deletions xdr/Stellar-contract.x
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ enum SCAddressType
SC_ADDRESS_TYPE_MUXED_ACCOUNT = 2,
SC_ADDRESS_TYPE_CLAIMABLE_BALANCE = 3,
SC_ADDRESS_TYPE_LIQUIDITY_POOL = 4
,
SC_ADDRESS_TYPE_MUXED_CONTRACT = 5
};

struct MuxedEd25519Account
Expand All @@ -191,6 +193,12 @@ struct MuxedEd25519Account
uint256 ed25519;
};

struct MuxedContract
{
uint64 id;
ContractID contractId;
};

union SCAddress switch (SCAddressType type)
{
case SC_ADDRESS_TYPE_ACCOUNT:
Expand All @@ -203,6 +211,8 @@ case SC_ADDRESS_TYPE_CLAIMABLE_BALANCE:
ClaimableBalanceID claimableBalanceId;
case SC_ADDRESS_TYPE_LIQUIDITY_POOL:
PoolID liquidityPoolId;
case SC_ADDRESS_TYPE_MUXED_CONTRACT:
MuxedContract muxedContract;
};

%struct SCVal;
Expand Down
11 changes: 11 additions & 0 deletions xdr/scval.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func (address ScAddress) String() (string, error) {
case ScAddressTypeScAddressTypeContract:
contractID := address.MustContractId()
result, err = strkey.Encode(strkey.VersionByteContract, contractID[:])
case ScAddressTypeScAddressTypeMuxedContract:
// CAP-0084 muxed contract addresses. There is not yet a strkey
// encoding for muxed contracts in this package, so we render the
// underlying base contract address (non-panicking). Surfacing the
// muxed id is deferred to horizon's processor.
contractID := address.MustMuxedContract().ContractId
result, err = strkey.Encode(strkey.VersionByteContract, contractID[:])
case ScAddressTypeScAddressTypeMuxedAccount:
payload := address.MustMuxedAccount()
muxed := MuxedAccount{
Expand Down Expand Up @@ -148,6 +155,10 @@ func (s ScAddress) Equals(o ScAddress) bool {
return sAccountID.Equals(o.MustAccountId())
case ScAddressTypeScAddressTypeContract:
return s.MustContractId() == o.MustContractId()
case ScAddressTypeScAddressTypeMuxedContract:
sMuxed := s.MustMuxedContract()
oMuxed := o.MustMuxedContract()
return sMuxed.Id == oMuxed.Id && sMuxed.ContractId == oMuxed.ContractId
case ScAddressTypeScAddressTypeClaimableBalance:
return s.MustClaimableBalanceId().MustV0() == o.MustClaimableBalanceId().MustV0()
case ScAddressTypeScAddressTypeLiquidityPool:
Expand Down
12 changes: 12 additions & 0 deletions xdr/scval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ func TestScAddressString(t *testing.T) {
},
expected: strkey.MustEncode(strkey.VersionByteContract, contractID[:]),
},
{
// CAP-0084: muxed contract renders the underlying base contract
// address; the muxed id is not yet surfaced in the string form.
address: ScAddress{
Type: ScAddressTypeScAddressTypeMuxedContract,
MuxedContract: &MuxedContract{
Id: 42,
ContractId: ContractId{1},
},
},
expected: strkey.MustEncode(strkey.VersionByteContract, contractID[:]),
},
{
address: ScAddress{
Type: ScAddressTypeScAddressTypeClaimableBalance,
Expand Down
2 changes: 1 addition & 1 deletion xdr/xdr_commit_generated.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8521b97ba0e8e71d746bf3bd73def92110e6a21f
787382ef2099cca168ca1cb282730d6b7b9e2f16
Loading
Loading