Skip to content

Commit

Permalink
Merges the final Protocol 20 XDR (i.e. for testnet) into soroban (#688
Browse files Browse the repository at this point in the history
)

* Update to latest curr and next XDRs (testnet final)
* Export curr instead of next!
* Update codebase to match new XDR schemas:
 - function invocation now needs an InvokeContractArgs structure
 - signatureArgs was a 0-elem vec, now an ScVal w/ 0-elem vec
 - bodyType is gone
 - metaDataSizeBytes is gone
 - some minor test stuff has been tweaked for readability
  • Loading branch information
Shaptic authored Sep 11, 2023
1 parent 7288730 commit a9567e5
Show file tree
Hide file tree
Showing 31 changed files with 13,022 additions and 4,957 deletions.
13 changes: 9 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
XDR_BASE_URL_CURR=https://github.com/stellar/stellar-xdr/raw/curr
XDR_BASE_URL_CURR=https://github.com/stellar/stellar-xdr/raw/9ac02641139e6717924fdad716f6e958d0168491
XDR_BASE_LOCAL_CURR=xdr/curr
XDR_FILES_CURR= \
Stellar-SCP.x \
Stellar-ledger-entries.x \
Stellar-ledger.x \
Stellar-overlay.x \
Stellar-transaction.x \
Stellar-types.x
Stellar-types.x \
Stellar-contract.x \
Stellar-contract-env-meta.x \
Stellar-contract-meta.x \
Stellar-contract-spec.x \
Stellar-contract-config-setting.x
XDR_FILES_LOCAL_CURR=$(addprefix xdr/curr/,$(XDR_FILES_CURR))

XDR_BASE_URL_NEXT=https://github.com/stellar/stellar-xdr/raw/e372df9f677961aac04c5a4cc80a3667f310b29f
XDR_BASE_URL_NEXT=https://github.com/stellar/stellar-xdr/raw/440dc9512b6e72cf84965641c5eb495d6043ed73
XDR_BASE_LOCAL_NEXT=xdr/next
XDR_FILES_NEXT= \
Stellar-SCP.x \
Expand All @@ -25,7 +30,7 @@ XDR_FILES_NEXT= \
Stellar-contract-config-setting.x
XDR_FILES_LOCAL_NEXT=$(addprefix xdr/next/,$(XDR_FILES_NEXT))

XDRGEN_COMMIT=8d303b1
XDRGEN_COMMIT=master
DTSXDR_COMMIT=master

all: generate
Expand Down
11 changes: 7 additions & 4 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,25 @@ export function buildAuthEntry(envelope, signature, publicKey) {
address: new Address(publicKey).toScAddress(),
nonce: auth.nonce(),
signatureExpirationLedger: auth.signatureExpirationLedger(),
signatureArgs: [
// This structure is defined here:
// https://soroban.stellar.org/docs/fundamentals-and-concepts/invoking-contracts-with-transactions#stellar-account-signatures
//
// Encoding a contract structure as an ScVal means the keys are supposed
// to be symbols, hence the forced typing here.
signature: xdr.ScVal.scvVec([
nativeToScVal(
{
public_key: StrKey.decodeEd25519PublicKey(publicKey),
signature
},
{
// force the keys to be interpreted as symbols (expected for
// Soroban [contracttype]s)
type: {
public_key: ['symbol', null],
signature: ['symbol', null]
}
}
)
]
])
})
)
});
Expand Down
30 changes: 14 additions & 16 deletions src/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { StrKey } from './strkey';
* @param {string} contractId - ID of the contract (ex.
* `CA3D5KRYM6CB7OWQ6TWYRR3Z4T7GNZLKERYNZGGA5SOAOPIFY6YQGAXE`).
*/
// TODO: Support contract deployment, maybe?
export class Contract {
constructor(contractId) {
try {
Expand Down Expand Up @@ -49,18 +48,21 @@ export class Contract {
/**
* Returns an operation that will invoke this contract call.
*
* @param {string} method - name of the method to call
* @param {...xdr.ScVal} params - arguments to pass to the function call
* @returns {xdr.Operation} Build a InvokeHostFunctionOp operation to call the
* contract.
* @param {string} method name of the method to call
* @param {...xdr.ScVal} params arguments to pass to the function call
*
* @returns {xdr.Operation} an InvokeHostFunctionOp operation to call the
* contract with the given method and parameters
*/
call(method, ...params) {
return Operation.invokeHostFunction({
func: xdr.HostFunction.hostFunctionTypeInvokeContract([
this.address().toScVal(),
xdr.ScVal.scvSymbol(method),
...params
]),
func: xdr.HostFunction.hostFunctionTypeInvokeContract(
new xdr.InvokeContractArgs({
contractAddress: this.address().toScAddress(),
functionName: xdr.ScVal.scvSymbol(method),
args: params
})
),
auth: []
});
}
Expand All @@ -76,17 +78,13 @@ export class Contract {
getFootprint() {
return [
xdr.LedgerKey.contractCode(
new xdr.LedgerKeyContractCode({
hash: this._id,
bodyType: xdr.ContractEntryBodyType.dataEntry()
})
new xdr.LedgerKeyContractCode({ hash: this._id })
),
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contract: this.address().toScAddress(),
key: xdr.ScVal.scvLedgerKeyContractInstance(),
durability: xdr.ContractDataDurability.persistent(),
bodyType: xdr.ContractEntryBodyType.dataEntry()
durability: xdr.ContractDataDurability.persistent()
})
)
];
Expand Down
Loading

0 comments on commit a9567e5

Please sign in to comment.