Skip to content

Commit

Permalink
Soroban value overhaul (#582)
Browse files Browse the repository at this point in the history
* Update xdr for value overhaul

* Fixing address & contract for new xdr

* 8.2.2-soroban.12
  • Loading branch information
Paul Bellamy authored Mar 14, 2023
1 parent b1d18d5 commit df4f2fc
Show file tree
Hide file tree
Showing 13 changed files with 882 additions and 654 deletions.
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

0 comments on commit df4f2fc

Please sign in to comment.