Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soroban value overhaul #582

Merged
merged 3 commits into from
Mar 14, 2023
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stellar-base",
"version": "8.2.2-soroban.11",
"version": "8.2.2-soroban.12",
"description": "Low level stellar support library",
"main": "./lib/index.js",
"types": "./types/index.d.ts",
Expand Down
29 changes: 28 additions & 1 deletion src/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ export class Address {
return new Address(StrKey.encodeContract(buffer));
}

/**
* Convert this from an xdr.ScVal type
*
* @param {xdr.ScVal} scVal - The xdr.ScVal type to parse
* @returns {Address}
*/
static fromScVal(scVal) {
return Address.fromScAddress(scVal.address());
}

/**
* Convert this from an xdr.ScAddress type
*
* @param {xdr.ScAddress} scAddress - The xdr.ScAddress type to parse
* @returns {Address}
*/
static fromScAddress(scAddress) {
switch (scAddress.switch()) {
case xdr.ScAddressType.scAddressTypeAccount():
return Address.account(scAddress.accountId().ed25519());
case xdr.ScAddressType.scAddressTypeContract():
return Address.contract(scAddress.contractId());
default:
throw new Error('Unsupported address type');
}
}

/**
* Serialize an address to string.
*
Expand All @@ -79,7 +106,7 @@ export class Address {
* @returns {xdr.ScVal}
*/
toScVal() {
return xdr.ScVal.scvObject(xdr.ScObject.scoAddress(this.toScAddress()));
return xdr.ScVal.scvAddress(this.toScAddress());
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class Contract {
const contractId = Buffer.from(this._id, 'hex');
return Operation.invokeHostFunction({
function: xdr.HostFunction.hostFunctionTypeInvokeContract([
xdr.ScVal.scvObject(xdr.ScObject.scoBytes(contractId)),
xdr.ScVal.scvBytes(contractId),
xdr.ScVal.scvSymbol(method),
...params
]),
Expand All @@ -49,7 +49,7 @@ export class Contract {
xdr.LedgerKey.contractData(
new xdr.LedgerKeyContractData({
contractId,
key: xdr.ScVal.scvStatic(xdr.ScStatic.scsLedgerKeyContractCode())
key: xdr.ScVal.scvLedgerKeyContractExecutable()
})
)
],
Expand Down
Loading