Skip to content

Commit

Permalink
Added QPI::numberOfPossessedShares().
Browse files Browse the repository at this point in the history
  • Loading branch information
CFB-QUBIC committed Mar 26, 2024
1 parent 2e64e7a commit 009b980
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 2 deletions.
81 changes: 79 additions & 2 deletions src/qubic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1788,8 +1867,6 @@ static long long __transferShareOwnershipAndPossession(unsigned long long assetN
goto iteration;
}
}

return 0;
}

static unsigned char __year()
Expand Down
1 change: 1 addition & 0 deletions src/smart_contracts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/smart_contracts/qpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 009b980

Please sign in to comment.