diff --git a/src/qubic.cpp b/src/qubic.cpp index f60a9f82..69d8a1df 100644 --- a/src/qubic.cpp +++ b/src/qubic.cpp @@ -1636,6 +1636,85 @@ static m256i __nextId(const m256i& currentId) return _mm256_setzero_si256(); } +static long long __numberOfPossessedShares(unsigned long long assetName, const m256i& issuer, const m256i& owner, const m256i& possessor, unsigned short ownershipManagingContractIndex, unsigned short possessionManagingContractIndex) +{ + ACQUIRE(universeLock); + + int issuanceIndex = issuer.m256i_u32[0] & (ASSETS_CAPACITY - 1); +iteration: + if (assets[issuanceIndex].varStruct.issuance.type == EMPTY) + { + RELEASE(universeLock); + + return 0; + } + else + { + if (assets[issuanceIndex].varStruct.issuance.type == ISSUANCE + && ((*((unsigned long long*)assets[issuanceIndex].varStruct.issuance.name)) & 0xFFFFFFFFFFFFFF) == assetName + && assets[issuanceIndex].varStruct.issuance.publicKey == issuer) + { + int ownershipIndex = owner.m256i_u32[0] & (ASSETS_CAPACITY - 1); + iteration2: + if (assets[ownershipIndex].varStruct.ownership.type == EMPTY) + { + RELEASE(universeLock); + + return 0; + } + else + { + if (assets[ownershipIndex].varStruct.ownership.type == OWNERSHIP + && assets[ownershipIndex].varStruct.ownership.issuanceIndex == issuanceIndex + && assets[ownershipIndex].varStruct.ownership.publicKey == owner + && assets[ownershipIndex].varStruct.ownership.managingContractIndex == ownershipManagingContractIndex) + { + int possessionIndex = possessor.m256i_u32[0] & (ASSETS_CAPACITY - 1); + iteration3: + if (assets[possessionIndex].varStruct.possession.type == EMPTY) + { + RELEASE(universeLock); + + return 0; + } + else + { + if (assets[possessionIndex].varStruct.possession.type == POSSESSION + && assets[possessionIndex].varStruct.possession.ownershipIndex == ownershipIndex + && assets[possessionIndex].varStruct.possession.publicKey == possessor + && assets[possessionIndex].varStruct.possession.managingContractIndex == possessionManagingContractIndex) + { + const long long numberOfPossessedShares = assets[possessionIndex].varStruct.possession.numberOfShares; + + RELEASE(universeLock); + + return numberOfPossessedShares; + } + else + { + possessionIndex = (possessionIndex + 1) & (ASSETS_CAPACITY - 1); + + goto iteration3; + } + } + } + else + { + ownershipIndex = (ownershipIndex + 1) & (ASSETS_CAPACITY - 1); + + goto iteration2; + } + } + } + else + { + issuanceIndex = (issuanceIndex + 1) & (ASSETS_CAPACITY - 1); + + goto iteration; + } + } +} + static m256i __originator() { return ::originator; @@ -1788,8 +1867,6 @@ static long long __transferShareOwnershipAndPossession(unsigned long long assetN goto iteration; } } - - return 0; } static unsigned char __year() diff --git a/src/smart_contracts.h b/src/smart_contracts.h index e86a65bc..6b57aa71 100644 --- a/src/smart_contracts.h +++ b/src/smart_contracts.h @@ -35,6 +35,7 @@ static unsigned short __millisecond(); static unsigned char __minute(); static unsigned char __month(); static m256i __nextId(const m256i&); +static long long __numberOfPossessedShares(unsigned long long, const m256i&, const m256i&, const m256i&, unsigned short, unsigned short); static m256i __originator(); static void __registerUserFunction(USER_FUNCTION, unsigned short, unsigned short, unsigned short); static void __registerUserProcedure(USER_PROCEDURE, unsigned short, unsigned short, unsigned short); diff --git a/src/smart_contracts/qpi.h b/src/smart_contracts/qpi.h index 871c913c..ab5f9ed8 100644 --- a/src/smart_contracts/qpi.h +++ b/src/smart_contracts/qpi.h @@ -6034,6 +6034,17 @@ namespace QPI return ::__nextId(currentId); } + static sint64 numberOfPossessedShares( + uint64 assetName, + id issuer, + id owner, + id possessor, + uint16 ownershipManagingContractIndex, + uint16 possessionManagingContractIndex + ) { + return ::__numberOfPossessedShares(assetName, issuer, owner, possessor, ownershipManagingContractIndex, possessionManagingContractIndex); + } + static id originator( ) { // Returns the id of the user who has triggered the whole chain of invocations with their transaction; returns NULL_ID if there has been no user return ::__originator();