diff --git a/package.json b/package.json index ee37d3cc..825fbbf2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "stellar-base", - "version": "8.2.2-soroban.6", + "version": "8.2.2-soroban.7", "description": "Low level stellar support library", "main": "./lib/index.js", "types": "./types/index.d.ts", diff --git a/src/contract.js b/src/contract.js index bd6f2c9c..d897723f 100644 --- a/src/contract.js +++ b/src/contract.js @@ -54,7 +54,8 @@ export class Contract { ) ], readWrite: [] - }) + }), + auth: [] }); } } diff --git a/src/generated/next_generated.js b/src/generated/next_generated.js index 2f4f4247..ae4175f3 100644 --- a/src/generated/next_generated.js +++ b/src/generated/next_generated.js @@ -1987,7 +1987,8 @@ xdr.union("LedgerKey", { // ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, // ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, // ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11, -// ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12 +// ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12, +// ENVELOPE_TYPE_CONTRACT_AUTH = 13 // }; // // =========================================================================== @@ -2005,6 +2006,7 @@ xdr.enum("EnvelopeType", { envelopeTypeContractIdFromAsset: 10, envelopeTypeContractIdFromSourceAccount: 11, envelopeTypeCreateContractArgs: 12, + envelopeTypeContractAuth: 13, }); // === xdr source ============================================================ @@ -3489,6 +3491,20 @@ xdr.enum("SurveyMessageCommandType", { surveyTopology: 0, }); +// === xdr source ============================================================ +// +// enum SurveyMessageResponseType +// { +// SURVEY_TOPOLOGY_RESPONSE_V0 = 0, +// SURVEY_TOPOLOGY_RESPONSE_V1 = 1 +// }; +// +// =========================================================================== +xdr.enum("SurveyMessageResponseType", { + surveyTopologyResponseV0: 0, + surveyTopologyResponseV1: 1, +}); + // === xdr source ============================================================ // // struct SurveyRequestMessage @@ -3615,23 +3631,71 @@ xdr.typedef("PeerStatList", xdr.varArray(xdr.lookup("PeerStats"), 25)); // === xdr source ============================================================ // -// struct TopologyResponseBody +// struct TopologyResponseBodyV0 +// { +// PeerStatList inboundPeers; +// PeerStatList outboundPeers; +// +// uint32 totalInboundPeerCount; +// uint32 totalOutboundPeerCount; +// }; +// +// =========================================================================== +xdr.struct("TopologyResponseBodyV0", [ + ["inboundPeers", xdr.lookup("PeerStatList")], + ["outboundPeers", xdr.lookup("PeerStatList")], + ["totalInboundPeerCount", xdr.lookup("Uint32")], + ["totalOutboundPeerCount", xdr.lookup("Uint32")], +]); + +// === xdr source ============================================================ +// +// struct TopologyResponseBodyV1 // { // PeerStatList inboundPeers; // PeerStatList outboundPeers; // // uint32 totalInboundPeerCount; // uint32 totalOutboundPeerCount; +// +// uint32 maxInboundPeerCount; +// uint32 maxOutboundPeerCount; // }; // // =========================================================================== -xdr.struct("TopologyResponseBody", [ +xdr.struct("TopologyResponseBodyV1", [ ["inboundPeers", xdr.lookup("PeerStatList")], ["outboundPeers", xdr.lookup("PeerStatList")], ["totalInboundPeerCount", xdr.lookup("Uint32")], ["totalOutboundPeerCount", xdr.lookup("Uint32")], + ["maxInboundPeerCount", xdr.lookup("Uint32")], + ["maxOutboundPeerCount", xdr.lookup("Uint32")], ]); +// === xdr source ============================================================ +// +// union SurveyResponseBody switch (SurveyMessageResponseType type) +// { +// case SURVEY_TOPOLOGY_RESPONSE_V0: +// TopologyResponseBodyV0 topologyResponseBodyV0; +// case SURVEY_TOPOLOGY_RESPONSE_V1: +// TopologyResponseBodyV1 topologyResponseBodyV1; +// }; +// +// =========================================================================== +xdr.union("SurveyResponseBody", { + switchOn: xdr.lookup("SurveyMessageResponseType"), + switchName: "type", + switches: [ + ["surveyTopologyResponseV0", "topologyResponseBodyV0"], + ["surveyTopologyResponseV1", "topologyResponseBodyV1"], + ], + arms: { + topologyResponseBodyV0: xdr.lookup("TopologyResponseBodyV0"), + topologyResponseBodyV1: xdr.lookup("TopologyResponseBodyV1"), + }, +}); + // === xdr source ============================================================ // // const TX_ADVERT_VECTOR_MAX_SIZE = 1000; @@ -3684,26 +3748,6 @@ xdr.struct("FloodDemand", [ ["txHashes", xdr.lookup("TxDemandVector")], ]); -// === xdr source ============================================================ -// -// union SurveyResponseBody switch (SurveyMessageCommandType type) -// { -// case SURVEY_TOPOLOGY: -// TopologyResponseBody topologyResponseBody; -// }; -// -// =========================================================================== -xdr.union("SurveyResponseBody", { - switchOn: xdr.lookup("SurveyMessageCommandType"), - switchName: "type", - switches: [ - ["surveyTopology", "topologyResponseBody"], - ], - arms: { - topologyResponseBody: xdr.lookup("TopologyResponseBody"), - }, -}); - // === xdr source ============================================================ // // union StellarMessage switch (MessageType type) @@ -3751,9 +3795,9 @@ xdr.union("SurveyResponseBody", { // // // Pull mode // case FLOOD_ADVERT: -// FloodAdvert floodAdvert; +// FloodAdvert floodAdvert; // case FLOOD_DEMAND: -// FloodDemand floodDemand; +// FloodDemand floodDemand; // }; // // =========================================================================== @@ -4607,6 +4651,54 @@ xdr.union("HostFunction", { }, }); +// === xdr source ============================================================ +// +// struct AuthorizedInvocation +// { +// Hash contractID; +// SCSymbol functionName; +// SCVec args; +// AuthorizedInvocation subInvocations<>; +// }; +// +// =========================================================================== +xdr.struct("AuthorizedInvocation", [ + ["contractId", xdr.lookup("Hash")], + ["functionName", xdr.lookup("ScSymbol")], + ["args", xdr.lookup("ScVec")], + ["subInvocations", xdr.varArray(xdr.lookup("AuthorizedInvocation"), 2147483647)], +]); + +// === xdr source ============================================================ +// +// struct AddressWithNonce +// { +// SCAddress address; +// uint64 nonce; +// }; +// +// =========================================================================== +xdr.struct("AddressWithNonce", [ + ["address", xdr.lookup("ScAddress")], + ["nonce", xdr.lookup("Uint64")], +]); + +// === xdr source ============================================================ +// +// struct ContractAuth +// { +// AddressWithNonce* addressWithNonce; // not present for invoker +// AuthorizedInvocation rootInvocation; +// SCVec signatureArgs; +// }; +// +// =========================================================================== +xdr.struct("ContractAuth", [ + ["addressWithNonce", xdr.option(xdr.lookup("AddressWithNonce"))], + ["rootInvocation", xdr.lookup("AuthorizedInvocation")], + ["signatureArgs", xdr.lookup("ScVec")], +]); + // === xdr source ============================================================ // // struct InvokeHostFunctionOp @@ -4615,12 +4707,16 @@ xdr.union("HostFunction", { // HostFunction function; // // The footprint for this invocation // LedgerFootprint footprint; +// // Per-address authorizations for this host fn +// // Currently only supported for INVOKE_CONTRACT function +// ContractAuth auth<>; // }; // // =========================================================================== xdr.struct("InvokeHostFunctionOp", [ ["function", xdr.lookup("HostFunction")], ["footprint", xdr.lookup("LedgerFootprint")], + ["auth", xdr.varArray(xdr.lookup("ContractAuth"), 2147483647)], ]); // === xdr source ============================================================ @@ -4922,6 +5018,20 @@ xdr.struct("HashIdPreimageCreateContractArgs", [ ["salt", xdr.lookup("Uint256")], ]); +// === xdr source ============================================================ +// +// struct +// { +// Hash networkID; +// AuthorizedInvocation invocation; +// } +// +// =========================================================================== +xdr.struct("HashIdPreimageContractAuth", [ + ["networkId", xdr.lookup("Hash")], + ["invocation", xdr.lookup("AuthorizedInvocation")], +]); + // === xdr source ============================================================ // // union HashIDPreimage switch (EnvelopeType type) @@ -4975,7 +5085,13 @@ xdr.struct("HashIdPreimageCreateContractArgs", [ // Hash networkID; // SCContractCode source; // uint256 salt; -// } createContractArgs; +// } createContractArgs; +// case ENVELOPE_TYPE_CONTRACT_AUTH: +// struct +// { +// Hash networkID; +// AuthorizedInvocation invocation; +// } contractAuth; // }; // // =========================================================================== @@ -4990,6 +5106,7 @@ xdr.union("HashIdPreimage", { ["envelopeTypeContractIdFromAsset", "fromAsset"], ["envelopeTypeContractIdFromSourceAccount", "sourceAccountContractId"], ["envelopeTypeCreateContractArgs", "createContractArgs"], + ["envelopeTypeContractAuth", "contractAuth"], ], arms: { operationId: xdr.lookup("HashIdPreimageOperationId"), @@ -4999,6 +5116,7 @@ xdr.union("HashIdPreimage", { fromAsset: xdr.lookup("HashIdPreimageFromAsset"), sourceAccountContractId: xdr.lookup("HashIdPreimageSourceAccountContractId"), createContractArgs: xdr.lookup("HashIdPreimageCreateContractArgs"), + contractAuth: xdr.lookup("HashIdPreimageContractAuth"), }, }); @@ -8367,7 +8485,8 @@ xdr.union("ScVal", { // SCO_I128 = 5, // SCO_BYTES = 6, // SCO_CONTRACT_CODE = 7, -// SCO_ACCOUNT_ID = 8 +// SCO_ADDRESS = 8, +// SCO_NONCE_KEY = 9 // // // TODO: add more // }; @@ -8382,7 +8501,8 @@ xdr.enum("ScObjectType", { scoI128: 5, scoBytes: 6, scoContractCode: 7, - scoAccountId: 8, + scoAddress: 8, + scoNonceKey: 9, }); // === xdr source ============================================================ @@ -8473,6 +8593,44 @@ xdr.struct("Int128Parts", [ ["hi", xdr.lookup("Uint64")], ]); +// === xdr source ============================================================ +// +// enum SCAddressType +// { +// SC_ADDRESS_TYPE_ACCOUNT = 0, +// SC_ADDRESS_TYPE_CONTRACT = 1 +// }; +// +// =========================================================================== +xdr.enum("ScAddressType", { + scAddressTypeAccount: 0, + scAddressTypeContract: 1, +}); + +// === xdr source ============================================================ +// +// union SCAddress switch (SCAddressType type) +// { +// case SC_ADDRESS_TYPE_ACCOUNT: +// AccountID accountId; +// case SC_ADDRESS_TYPE_CONTRACT: +// Hash contractId; +// }; +// +// =========================================================================== +xdr.union("ScAddress", { + switchOn: xdr.lookup("ScAddressType"), + switchName: "type", + switches: [ + ["scAddressTypeAccount", "accountId"], + ["scAddressTypeContract", "contractId"], + ], + arms: { + accountId: xdr.lookup("AccountId"), + contractId: xdr.lookup("Hash"), + }, +}); + // === xdr source ============================================================ // // union SCObject switch (SCObjectType type) @@ -8493,8 +8651,10 @@ xdr.struct("Int128Parts", [ // opaque bin; // case SCO_CONTRACT_CODE: // SCContractCode contractCode; -// case SCO_ACCOUNT_ID: -// AccountID accountID; +// case SCO_ADDRESS: +// SCAddress address; +// case SCO_NONCE_KEY: +// SCAddress nonceAddress; // }; // // =========================================================================== @@ -8510,7 +8670,8 @@ xdr.union("ScObject", { ["scoI128", "i128"], ["scoBytes", "bin"], ["scoContractCode", "contractCode"], - ["scoAccountId", "accountId"], + ["scoAddress", "address"], + ["scoNonceKey", "nonceAddress"], ], arms: { vec: xdr.lookup("ScVec"), @@ -8521,7 +8682,8 @@ xdr.union("ScObject", { i128: xdr.lookup("Int128Parts"), bin: xdr.varOpaque(SCVAL_LIMIT), contractCode: xdr.lookup("ScContractCode"), - accountId: xdr.lookup("AccountId"), + address: xdr.lookup("ScAddress"), + nonceAddress: xdr.lookup("ScAddress"), }, }); @@ -8576,7 +8738,7 @@ xdr.union("ScEnvMetaEntry", { // SC_SPEC_TYPE_STATUS = 10, // SC_SPEC_TYPE_BYTES = 11, // SC_SPEC_TYPE_INVOKER = 12, -// SC_SPEC_TYPE_ACCOUNT_ID = 13, +// SC_SPEC_TYPE_ADDRESS = 13, // // // Types with parameters. // SC_SPEC_TYPE_OPTION = 1000, @@ -8606,7 +8768,7 @@ xdr.enum("ScSpecType", { scSpecTypeStatus: 10, scSpecTypeBytes: 11, scSpecTypeInvoker: 12, - scSpecTypeAccountId: 13, + scSpecTypeAddress: 13, scSpecTypeOption: 1000, scSpecTypeResult: 1001, scSpecTypeVec: 1002, @@ -8733,8 +8895,7 @@ xdr.struct("ScSpecTypeUdt", [ // case SC_SPEC_TYPE_BITSET: // case SC_SPEC_TYPE_STATUS: // case SC_SPEC_TYPE_BYTES: -// case SC_SPEC_TYPE_INVOKER: -// case SC_SPEC_TYPE_ACCOUNT_ID: +// case SC_SPEC_TYPE_ADDRESS: // void; // case SC_SPEC_TYPE_OPTION: // SCSpecTypeOption option; @@ -8771,8 +8932,7 @@ xdr.union("ScSpecTypeDef", { ["scSpecTypeBitset", xdr.void()], ["scSpecTypeStatus", xdr.void()], ["scSpecTypeBytes", xdr.void()], - ["scSpecTypeInvoker", xdr.void()], - ["scSpecTypeAccountId", xdr.void()], + ["scSpecTypeAddress", xdr.void()], ["scSpecTypeOption", "option"], ["scSpecTypeResult", "result"], ["scSpecTypeVec", "vec"], diff --git a/src/operation.js b/src/operation.js index 1afeb25b..7c0eb697 100644 --- a/src/operation.js +++ b/src/operation.js @@ -392,6 +392,7 @@ export class Operation { result.type = 'invokeHostFunction'; result.function = attrs.function(); result.footprint = attrs.footprint(); + result.auth = attrs.auth(); break; } default: { diff --git a/src/operations/invoke_host_function.js b/src/operations/invoke_host_function.js index f798c5a5..f75bf50a 100644 --- a/src/operations/invoke_host_function.js +++ b/src/operations/invoke_host_function.js @@ -8,8 +8,8 @@ import xdr from '../xdr'; * * @param {object} opts - options object * @param {xdr.HostFunction} opts.function - host function to invoke - * @param {xdr.LedgerFootprint} [opts.footprint] - operation source account (defaults to - * transaction source) + * @param {xdr.LedgerFootprint} [opts.footprint] - footprint of the ledger state accessed by this call + * @param {xdr.ContractAuth[]} [opts.auth] - authorizations for the call * * @returns {xdr.Operation} an Invoke Host Function operation (xdr.InvokeHostFunctionOp) */ @@ -20,7 +20,8 @@ export function invokeHostFunction(opts) { const invokeHostFunctionOp = new xdr.InvokeHostFunctionOp({ function: opts.function, - footprint: opts.footprint + footprint: opts.footprint, + auth: opts.auth }); const opAttributes = { body: xdr.OperationBody.invokeHostFunction(invokeHostFunctionOp) diff --git a/types/index.d.ts b/types/index.d.ts index c68d8de8..0f979599 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -528,6 +528,7 @@ export namespace OperationOptions { function: xdr.HostFunction; parameters: xdr.ScVal[]; footprint: xdr.LedgerFootprint; + auth: xdr.ContractAuth[]; } } export type OperationOptions = diff --git a/types/next.d.ts b/types/next.d.ts index 5cdc7b60..aa7e4fe9 100644 --- a/types/next.d.ts +++ b/types/next.d.ts @@ -1,4 +1,4 @@ -// Automatically generated on 2022-08-12T12:40:00+01:00 +// Automatically generated on 2023-02-02T13:12:00Z import { Operation } from './index'; export {}; @@ -455,9 +455,10 @@ export namespace xdr { | 'envelopeTypeContractIdFromContract' | 'envelopeTypeContractIdFromAsset' | 'envelopeTypeContractIdFromSourceAccount' - | 'envelopeTypeCreateContractArgs'; + | 'envelopeTypeCreateContractArgs' + | 'envelopeTypeContractAuth'; - readonly value: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; + readonly value: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13; static envelopeTypeTxV0(): EnvelopeType; @@ -484,6 +485,8 @@ export namespace xdr { static envelopeTypeContractIdFromSourceAccount(): EnvelopeType; static envelopeTypeCreateContractArgs(): EnvelopeType; + + static envelopeTypeContractAuth(): EnvelopeType; } class StellarValueType { @@ -713,6 +716,16 @@ export namespace xdr { static surveyTopology(): SurveyMessageCommandType; } + class SurveyMessageResponseType { + readonly name: 'surveyTopologyResponseV0' | 'surveyTopologyResponseV1'; + + readonly value: 0 | 1; + + static surveyTopologyResponseV0(): SurveyMessageResponseType; + + static surveyTopologyResponseV1(): SurveyMessageResponseType; + } + class OperationType { readonly name: | 'createAccount' @@ -2086,9 +2099,10 @@ export namespace xdr { | 'scoI128' | 'scoBytes' | 'scoContractCode' - | 'scoAccountId'; + | 'scoAddress' + | 'scoNonceKey'; - readonly value: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8; + readonly value: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; static scoVec(): ScObjectType; @@ -2106,7 +2120,9 @@ export namespace xdr { static scoContractCode(): ScObjectType; - static scoAccountId(): ScObjectType; + static scoAddress(): ScObjectType; + + static scoNonceKey(): ScObjectType; } class ScContractCodeType { @@ -2119,6 +2135,16 @@ export namespace xdr { static sccontractCodeToken(): ScContractCodeType; } + class ScAddressType { + readonly name: 'scAddressTypeAccount' | 'scAddressTypeContract'; + + readonly value: 0 | 1; + + static scAddressTypeAccount(): ScAddressType; + + static scAddressTypeContract(): ScAddressType; + } + class ScEnvMetaKind { readonly name: 'scEnvMetaKindInterfaceVersion'; @@ -2142,7 +2168,7 @@ export namespace xdr { | 'scSpecTypeStatus' | 'scSpecTypeBytes' | 'scSpecTypeInvoker' - | 'scSpecTypeAccountId' + | 'scSpecTypeAddress' | 'scSpecTypeOption' | 'scSpecTypeResult' | 'scSpecTypeVec' @@ -2202,7 +2228,7 @@ export namespace xdr { static scSpecTypeInvoker(): ScSpecType; - static scSpecTypeAccountId(): ScSpecType; + static scSpecTypeAddress(): ScSpecType; static scSpecTypeOption(): ScSpecType; @@ -5319,7 +5345,7 @@ export namespace xdr { static validateXDR(input: string, format: 'hex' | 'base64'): boolean; } - class TopologyResponseBody { + class TopologyResponseBodyV0 { constructor(attributes: { inboundPeers: PeerStats[]; outboundPeers: PeerStats[]; @@ -5339,20 +5365,66 @@ export namespace xdr { toXDR(format: 'hex' | 'base64'): string; - static read(io: Buffer): TopologyResponseBody; + static read(io: Buffer): TopologyResponseBodyV0; - static write(value: TopologyResponseBody, io: Buffer): void; + static write(value: TopologyResponseBodyV0, io: Buffer): void; - static isValid(value: TopologyResponseBody): boolean; + static isValid(value: TopologyResponseBodyV0): boolean; - static toXDR(value: TopologyResponseBody): Buffer; + static toXDR(value: TopologyResponseBodyV0): Buffer; - static fromXDR(input: Buffer, format?: 'raw'): TopologyResponseBody; + static fromXDR(input: Buffer, format?: 'raw'): TopologyResponseBodyV0; static fromXDR( input: string, format: 'hex' | 'base64' - ): TopologyResponseBody; + ): TopologyResponseBodyV0; + + static validateXDR(input: Buffer, format?: 'raw'): boolean; + + static validateXDR(input: string, format: 'hex' | 'base64'): boolean; + } + + class TopologyResponseBodyV1 { + constructor(attributes: { + inboundPeers: PeerStats[]; + outboundPeers: PeerStats[]; + totalInboundPeerCount: number; + totalOutboundPeerCount: number; + maxInboundPeerCount: number; + maxOutboundPeerCount: number; + }); + + inboundPeers(value?: PeerStats[]): PeerStats[]; + + outboundPeers(value?: PeerStats[]): PeerStats[]; + + totalInboundPeerCount(value?: number): number; + + totalOutboundPeerCount(value?: number): number; + + maxInboundPeerCount(value?: number): number; + + maxOutboundPeerCount(value?: number): number; + + toXDR(format?: 'raw'): Buffer; + + toXDR(format: 'hex' | 'base64'): string; + + static read(io: Buffer): TopologyResponseBodyV1; + + static write(value: TopologyResponseBodyV1, io: Buffer): void; + + static isValid(value: TopologyResponseBodyV1): boolean; + + static toXDR(value: TopologyResponseBodyV1): Buffer; + + static fromXDR(input: Buffer, format?: 'raw'): TopologyResponseBodyV1; + + static fromXDR( + input: string, + format: 'hex' | 'base64' + ): TopologyResponseBodyV1; static validateXDR(input: Buffer, format?: 'raw'): boolean; @@ -6388,16 +6460,121 @@ export namespace xdr { static validateXDR(input: string, format: 'hex' | 'base64'): boolean; } + class AuthorizedInvocation { + constructor(attributes: { + contractId: Buffer; + functionName: string | Buffer; + args: ScVal[]; + subInvocations: AuthorizedInvocation[]; + }); + + contractId(value?: Buffer): Buffer; + + functionName(value?: string | Buffer): string | Buffer; + + args(value?: ScVal[]): ScVal[]; + + subInvocations(value?: AuthorizedInvocation[]): AuthorizedInvocation[]; + + toXDR(format?: 'raw'): Buffer; + + toXDR(format: 'hex' | 'base64'): string; + + static read(io: Buffer): AuthorizedInvocation; + + static write(value: AuthorizedInvocation, io: Buffer): void; + + static isValid(value: AuthorizedInvocation): boolean; + + static toXDR(value: AuthorizedInvocation): Buffer; + + static fromXDR(input: Buffer, format?: 'raw'): AuthorizedInvocation; + + static fromXDR( + input: string, + format: 'hex' | 'base64' + ): AuthorizedInvocation; + + static validateXDR(input: Buffer, format?: 'raw'): boolean; + + static validateXDR(input: string, format: 'hex' | 'base64'): boolean; + } + + class AddressWithNonce { + constructor(attributes: { address: ScAddress; nonce: Uint64 }); + + address(value?: ScAddress): ScAddress; + + nonce(value?: Uint64): Uint64; + + toXDR(format?: 'raw'): Buffer; + + toXDR(format: 'hex' | 'base64'): string; + + static read(io: Buffer): AddressWithNonce; + + static write(value: AddressWithNonce, io: Buffer): void; + + static isValid(value: AddressWithNonce): boolean; + + static toXDR(value: AddressWithNonce): Buffer; + + static fromXDR(input: Buffer, format?: 'raw'): AddressWithNonce; + + static fromXDR(input: string, format: 'hex' | 'base64'): AddressWithNonce; + + static validateXDR(input: Buffer, format?: 'raw'): boolean; + + static validateXDR(input: string, format: 'hex' | 'base64'): boolean; + } + + class ContractAuth { + constructor(attributes: { + addressWithNonce: null | AddressWithNonce; + rootInvocation: AuthorizedInvocation; + signatureArgs: ScVal[]; + }); + + addressWithNonce(value?: null | AddressWithNonce): null | AddressWithNonce; + + rootInvocation(value?: AuthorizedInvocation): AuthorizedInvocation; + + signatureArgs(value?: ScVal[]): ScVal[]; + + toXDR(format?: 'raw'): Buffer; + + toXDR(format: 'hex' | 'base64'): string; + + static read(io: Buffer): ContractAuth; + + static write(value: ContractAuth, io: Buffer): void; + + static isValid(value: ContractAuth): boolean; + + static toXDR(value: ContractAuth): Buffer; + + static fromXDR(input: Buffer, format?: 'raw'): ContractAuth; + + static fromXDR(input: string, format: 'hex' | 'base64'): ContractAuth; + + static validateXDR(input: Buffer, format?: 'raw'): boolean; + + static validateXDR(input: string, format: 'hex' | 'base64'): boolean; + } + class InvokeHostFunctionOp { constructor(attributes: { function: HostFunction; footprint: LedgerFootprint; + auth: ContractAuth[]; }); function(value?: HostFunction): HostFunction; footprint(value?: LedgerFootprint): LedgerFootprint; + auth(value?: ContractAuth[]): ContractAuth[]; + toXDR(format?: 'raw'): Buffer; toXDR(format: 'hex' | 'base64'): string; @@ -6724,6 +6901,40 @@ export namespace xdr { static validateXDR(input: string, format: 'hex' | 'base64'): boolean; } + class HashIdPreimageContractAuth { + constructor(attributes: { + networkId: Buffer; + invocation: AuthorizedInvocation; + }); + + networkId(value?: Buffer): Buffer; + + invocation(value?: AuthorizedInvocation): AuthorizedInvocation; + + toXDR(format?: 'raw'): Buffer; + + toXDR(format: 'hex' | 'base64'): string; + + static read(io: Buffer): HashIdPreimageContractAuth; + + static write(value: HashIdPreimageContractAuth, io: Buffer): void; + + static isValid(value: HashIdPreimageContractAuth): boolean; + + static toXDR(value: HashIdPreimageContractAuth): Buffer; + + static fromXDR(input: Buffer, format?: 'raw'): HashIdPreimageContractAuth; + + static fromXDR( + input: string, + format: 'hex' | 'base64' + ): HashIdPreimageContractAuth; + + static validateXDR(input: Buffer, format?: 'raw'): boolean; + + static validateXDR(input: string, format: 'hex' | 'base64'): boolean; + } + class TimeBounds { constructor(attributes: { minTime: TimePoint; maxTime: TimePoint }); @@ -9823,13 +10034,25 @@ export namespace xdr { } class SurveyResponseBody { - switch(): SurveyMessageCommandType; + switch(): SurveyMessageResponseType; - topologyResponseBody(value?: TopologyResponseBody): TopologyResponseBody; + topologyResponseBodyV0( + value?: TopologyResponseBodyV0 + ): TopologyResponseBodyV0; - static surveyTopology(value: TopologyResponseBody): SurveyResponseBody; + topologyResponseBodyV1( + value?: TopologyResponseBodyV1 + ): TopologyResponseBodyV1; - value(): TopologyResponseBody; + static surveyTopologyResponseV0( + value: TopologyResponseBodyV0 + ): SurveyResponseBody; + + static surveyTopologyResponseV1( + value: TopologyResponseBodyV1 + ): SurveyResponseBody; + + value(): TopologyResponseBodyV0 | TopologyResponseBodyV1; toXDR(format?: 'raw'): Buffer; @@ -10443,6 +10666,10 @@ export namespace xdr { value?: HashIdPreimageCreateContractArgs ): HashIdPreimageCreateContractArgs; + contractAuth( + value?: HashIdPreimageContractAuth + ): HashIdPreimageContractAuth; + static envelopeTypeOpId(value: HashIdPreimageOperationId): HashIdPreimage; static envelopeTypePoolRevokeOpId( @@ -10469,6 +10696,10 @@ export namespace xdr { value: HashIdPreimageCreateContractArgs ): HashIdPreimage; + static envelopeTypeContractAuth( + value: HashIdPreimageContractAuth + ): HashIdPreimage; + value(): | HashIdPreimageOperationId | HashIdPreimageRevokeId @@ -10476,7 +10707,8 @@ export namespace xdr { | HashIdPreimageContractId | HashIdPreimageFromAsset | HashIdPreimageSourceAccountContractId - | HashIdPreimageCreateContractArgs; + | HashIdPreimageCreateContractArgs + | HashIdPreimageContractAuth; toXDR(format?: 'raw'): Buffer; @@ -12641,6 +12873,40 @@ export namespace xdr { static validateXDR(input: string, format: 'hex' | 'base64'): boolean; } + class ScAddress { + switch(): ScAddressType; + + accountId(value?: AccountId): AccountId; + + contractId(value?: Buffer): Buffer; + + static scAddressTypeAccount(value: AccountId): ScAddress; + + static scAddressTypeContract(value: Buffer): ScAddress; + + value(): AccountId | Buffer; + + toXDR(format?: 'raw'): Buffer; + + toXDR(format: 'hex' | 'base64'): string; + + static read(io: Buffer): ScAddress; + + static write(value: ScAddress, io: Buffer): void; + + static isValid(value: ScAddress): boolean; + + static toXDR(value: ScAddress): Buffer; + + static fromXDR(input: Buffer, format?: 'raw'): ScAddress; + + static fromXDR(input: string, format: 'hex' | 'base64'): ScAddress; + + static validateXDR(input: Buffer, format?: 'raw'): boolean; + + static validateXDR(input: string, format: 'hex' | 'base64'): boolean; + } + class ScObject { switch(): ScObjectType; @@ -12660,7 +12926,9 @@ export namespace xdr { contractCode(value?: ScContractCode): ScContractCode; - accountId(value?: AccountId): AccountId; + address(value?: ScAddress): ScAddress; + + nonceAddress(value?: ScAddress): ScAddress; static scoVec(value: ScVal[]): ScObject; @@ -12678,7 +12946,9 @@ export namespace xdr { static scoContractCode(value: ScContractCode): ScObject; - static scoAccountId(value: AccountId): ScObject; + static scoAddress(value: ScAddress): ScObject; + + static scoNonceKey(value: ScAddress): ScObject; value(): | ScVal[] @@ -12689,7 +12959,8 @@ export namespace xdr { | Int128Parts | Buffer | ScContractCode - | AccountId; + | ScAddress + | ScAddress; toXDR(format?: 'raw'): Buffer; @@ -12785,9 +13056,7 @@ export namespace xdr { static scSpecTypeBytes(): ScSpecTypeDef; - static scSpecTypeInvoker(): ScSpecTypeDef; - - static scSpecTypeAccountId(): ScSpecTypeDef; + static scSpecTypeAddress(): ScSpecTypeDef; static scSpecTypeOption(value: ScSpecTypeOption): ScSpecTypeDef; diff --git a/xdr/next/Stellar-contract-spec.x b/xdr/next/Stellar-contract-spec.x index 31ce93db..6c5a5742 100644 --- a/xdr/next/Stellar-contract-spec.x +++ b/xdr/next/Stellar-contract-spec.x @@ -27,7 +27,7 @@ enum SCSpecType SC_SPEC_TYPE_STATUS = 10, SC_SPEC_TYPE_BYTES = 11, SC_SPEC_TYPE_INVOKER = 12, - SC_SPEC_TYPE_ACCOUNT_ID = 13, + SC_SPEC_TYPE_ADDRESS = 13, // Types with parameters. SC_SPEC_TYPE_OPTION = 1000, @@ -98,8 +98,7 @@ case SC_SPEC_TYPE_SYMBOL: case SC_SPEC_TYPE_BITSET: case SC_SPEC_TYPE_STATUS: case SC_SPEC_TYPE_BYTES: -case SC_SPEC_TYPE_INVOKER: -case SC_SPEC_TYPE_ACCOUNT_ID: +case SC_SPEC_TYPE_ADDRESS: void; case SC_SPEC_TYPE_OPTION: SCSpecTypeOption option; diff --git a/xdr/next/Stellar-contract.x b/xdr/next/Stellar-contract.x index 4dadc99b..2921c930 100644 --- a/xdr/next/Stellar-contract.x +++ b/xdr/next/Stellar-contract.x @@ -217,7 +217,8 @@ enum SCObjectType SCO_I128 = 5, SCO_BYTES = 6, SCO_CONTRACT_CODE = 7, - SCO_ACCOUNT_ID = 8 + SCO_ADDRESS = 8, + SCO_NONCE_KEY = 9 // TODO: add more }; @@ -255,6 +256,20 @@ struct Int128Parts { uint64 hi; }; +enum SCAddressType +{ + SC_ADDRESS_TYPE_ACCOUNT = 0, + SC_ADDRESS_TYPE_CONTRACT = 1 +}; + +union SCAddress switch (SCAddressType type) +{ +case SC_ADDRESS_TYPE_ACCOUNT: + AccountID accountId; +case SC_ADDRESS_TYPE_CONTRACT: + Hash contractId; +}; + union SCObject switch (SCObjectType type) { case SCO_VEC: @@ -273,7 +288,9 @@ case SCO_BYTES: opaque bin; case SCO_CONTRACT_CODE: SCContractCode contractCode; -case SCO_ACCOUNT_ID: - AccountID accountID; +case SCO_ADDRESS: + SCAddress address; +case SCO_NONCE_KEY: + SCAddress nonceAddress; }; } diff --git a/xdr/next/Stellar-ledger-entries.x b/xdr/next/Stellar-ledger-entries.x index 2616d2cd..55bdfe80 100644 --- a/xdr/next/Stellar-ledger-entries.x +++ b/xdr/next/Stellar-ledger-entries.x @@ -661,6 +661,7 @@ enum EnvelopeType ENVELOPE_TYPE_CONTRACT_ID_FROM_CONTRACT = 9, ENVELOPE_TYPE_CONTRACT_ID_FROM_ASSET = 10, ENVELOPE_TYPE_CONTRACT_ID_FROM_SOURCE_ACCOUNT = 11, - ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12 + ENVELOPE_TYPE_CREATE_CONTRACT_ARGS = 12, + ENVELOPE_TYPE_CONTRACT_AUTH = 13 }; } diff --git a/xdr/next/Stellar-overlay.x b/xdr/next/Stellar-overlay.x index ac679569..8203258c 100644 --- a/xdr/next/Stellar-overlay.x +++ b/xdr/next/Stellar-overlay.x @@ -47,6 +47,7 @@ struct Hello uint256 nonce; }; + // During the roll-out phrase, pull mode will be optional. // Therefore, we need a way to communicate with other nodes // that we want/don't want pull mode. @@ -126,6 +127,12 @@ enum SurveyMessageCommandType SURVEY_TOPOLOGY = 0 }; +enum SurveyMessageResponseType +{ + SURVEY_TOPOLOGY_RESPONSE_V0 = 0, + SURVEY_TOPOLOGY_RESPONSE_V1 = 1 +}; + struct SurveyRequestMessage { NodeID surveyorPeerID; @@ -180,7 +187,7 @@ struct PeerStats typedef PeerStats PeerStatList<25>; -struct TopologyResponseBody +struct TopologyResponseBodyV0 { PeerStatList inboundPeers; PeerStatList outboundPeers; @@ -189,6 +196,26 @@ struct TopologyResponseBody uint32 totalOutboundPeerCount; }; +struct TopologyResponseBodyV1 +{ + PeerStatList inboundPeers; + PeerStatList outboundPeers; + + uint32 totalInboundPeerCount; + uint32 totalOutboundPeerCount; + + uint32 maxInboundPeerCount; + uint32 maxOutboundPeerCount; +}; + +union SurveyResponseBody switch (SurveyMessageResponseType type) +{ +case SURVEY_TOPOLOGY_RESPONSE_V0: + TopologyResponseBodyV0 topologyResponseBodyV0; +case SURVEY_TOPOLOGY_RESPONSE_V1: + TopologyResponseBodyV1 topologyResponseBodyV1; +}; + const TX_ADVERT_VECTOR_MAX_SIZE = 1000; typedef Hash TxAdvertVector; @@ -205,12 +232,6 @@ struct FloodDemand TxDemandVector txHashes; }; -union SurveyResponseBody switch (SurveyMessageCommandType type) -{ -case SURVEY_TOPOLOGY: - TopologyResponseBody topologyResponseBody; -}; - union StellarMessage switch (MessageType type) { case ERROR_MSG: @@ -256,9 +277,9 @@ case SEND_MORE: // Pull mode case FLOOD_ADVERT: - FloodAdvert floodAdvert; + FloodAdvert floodAdvert; case FLOOD_DEMAND: - FloodDemand floodDemand; + FloodDemand floodDemand; }; union AuthenticatedMessage switch (uint32 v) diff --git a/xdr/next/Stellar-transaction.x b/xdr/next/Stellar-transaction.x index ba291dbb..9035c701 100644 --- a/xdr/next/Stellar-transaction.x +++ b/xdr/next/Stellar-transaction.x @@ -530,12 +530,36 @@ case HOST_FUNCTION_TYPE_INSTALL_CONTRACT_CODE: InstallContractCodeArgs installContractCodeArgs; }; +struct AuthorizedInvocation +{ + Hash contractID; + SCSymbol functionName; + SCVec args; + AuthorizedInvocation subInvocations<>; +}; + +struct AddressWithNonce +{ + SCAddress address; + uint64 nonce; +}; + +struct ContractAuth +{ + AddressWithNonce* addressWithNonce; // not present for invoker + AuthorizedInvocation rootInvocation; + SCVec signatureArgs; +}; + struct InvokeHostFunctionOp { // The host function to invoke HostFunction function; // The footprint for this invocation LedgerFootprint footprint; + // Per-address authorizations for this host fn + // Currently only supported for INVOKE_CONTRACT function + ContractAuth auth<>; }; /* An operation is the lowest unit of work that a transaction does */ @@ -653,7 +677,13 @@ case ENVELOPE_TYPE_CREATE_CONTRACT_ARGS: Hash networkID; SCContractCode source; uint256 salt; - } createContractArgs; + } createContractArgs; +case ENVELOPE_TYPE_CONTRACT_AUTH: + struct + { + Hash networkID; + AuthorizedInvocation invocation; + } contractAuth; }; enum MemoType