Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
136
Issues
136
List
Boards
Labels
Service Desk
Milestones
Merge Requests
44
Merge Requests
44
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
0661c86f
Commit
0661c86f
authored
2 hours ago
by
Mark Harding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(fix): add in repair job to change subscription ids
parent
34ddb380
master
No related merge requests found
Pipeline
#69565103
failed with stages
in 3 minutes and 12 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
112 additions
and
4 deletions
+112
-4
Subscriptions.php
Controllers/Cli/Payments/Subscriptions.php
+93
-0
Plus.php
Core/Wire/Delegates/Plus.php
+6
-1
Manager.php
Core/Wire/Manager.php
+13
-3
No files found.
Controllers/Cli/Payments/Subscriptions.php
View file @
0661c86f
...
...
@@ -7,8 +7,10 @@ use Minds\Core\Di\Di;
use
Minds\Core\Events\Dispatcher
;
use
Minds\Core\Payments\Subscriptions\Manager
;
use
Minds\Core\Payments\Subscriptions\Queue
;
use
Minds\Core\Security\ACL
;
use
Minds\Helpers\Cql
;
use
Minds\Interfaces
;
use
Minds\Core\Util\BigNumber
;
class
Subscriptions
extends
Cli\Controller
implements
Interfaces\CliControllerInterface
{
...
...
@@ -30,6 +32,8 @@ class Subscriptions extends Cli\Controller implements Interfaces\CliControllerIn
// Initialize events
\Minds\Core\Events\Defaults
::
_
();
ACL
::
$ignore
=
true
;
// we need to save to channels
/** @var Manager $manager */
$manager
=
Di
::
_
()
->
get
(
'Payments\Subscriptions\Manager'
);
...
...
@@ -42,6 +46,7 @@ class Subscriptions extends Cli\Controller implements Interfaces\CliControllerIn
foreach
(
$subscriptions
as
$subscription
)
{
$this
->
out
(
"Subscription:`
{
$subscription
->
getId
()
}
`"
);
$billing
=
date
(
'd-m-Y'
,
$subscription
->
getNextBilling
());
$user_guid
=
$subscription
->
getUser
()
->
guid
;
$this
->
out
(
"
\t
$billing
|
$user_guid
"
);
...
...
@@ -105,4 +110,92 @@ class Subscriptions extends Cli\Controller implements Interfaces\CliControllerIn
$this
->
out
(
"Done"
);
}
/**
* Sometimes, plus doesn't hit the delegate so the badge
* doesn't apply. This is designed to run regularly via
* a cron job to fix that
* @return void
*/
public
function
fixPlusWires
()
{
ACL
::
$ignore
=
true
;
// we need to save to channels
$delegate
=
new
\Minds\Core\Wire\Delegates\Plus
;
$usersLastPlus
=
[];
foreach
(
$this
->
getWires
(
false
)
as
$wire
)
{
$sender_guid
=
$wire
->
getSender
()
->
getGuid
();
$friendly
=
date
(
'd-m-Y'
,
$wire
->
getTimestamp
());
echo
"
\n
$sender_guid
"
;
if
(
$wire
->
getTimestamp
()
<
$usersLastPlus
[
$sender_guid
]
??
time
())
{
echo
"
$friendly
already given plus to this user"
;
continue
;
}
$usersLastPlus
[
$sender_guid
]
=
$wire
->
getTimestamp
();
$friendly
=
date
(
'd-m-Y'
,
$wire
->
getTimestamp
());
echo
"
$friendly
sending plus update (
{
$wire
->
getAmount
()
}
)"
;
if
(
$delegate
->
onWire
(
$wire
,
'offchain'
)
||
$delegate
->
onWire
(
$wire
,
'0x6f2548b1bee178a49c8ea09be6845f6aeaf3e8da'
))
{
echo
" done"
;
}
}
}
public
function
getWires
(
$onchain
=
false
)
{
$cql
=
\Minds\Core\Di\Di
::
_
()
->
get
(
'Database\Cassandra\Cql'
);
$prepared
=
new
\Minds\Core\Data\Cassandra\Prepared\Custom
;
$statement
=
"SELECT * FROM blockchain_transactions_mainnet WHERE contract='offchain:wire' and user_guid=? ALLOW FILTERING"
;
if
(
$onchain
)
{
$statement
=
"SELECT * FROM blockchain_transactions_mainnet WHERE wallet_address=? ALLOW FILTERING"
;
}
else
{
$statement
=
"SELECT * FROM blockchain_transactions_mainnet WHERE user_guid=? and amount>=? ALLOW FILTERING"
;
}
$offset
=
""
;
while
(
true
)
{
if
(
$onchain
)
{
$prepared
->
query
(
$statement
,
[
'0x6f2548b1bee178a49c8ea09be6845f6aeaf3e8da'
]);
}
else
{
$prepared
->
query
(
$statement
,
[
new
\Cassandra\Varint
(
730071191229833224
),
new
\Cassandra\Varint
(
5
)
]);
}
$prepared
->
setOpts
([
'paging_state_token'
=>
$offset
,
'page_size'
=>
100
,
]);
try
{
$result
=
$cql
->
request
(
$prepared
);
if
(
!
$result
)
{
break
;
}
$offset
=
$result
->
pagingStateToken
();
}
catch
(
\Exception
$e
)
{
var_dump
(
$e
);
}
foreach
(
$result
as
$row
)
{
$data
=
json_decode
(
$row
[
'data'
],
true
);
if
(
$row
[
'timestamp'
]
->
time
()
<
strtotime
(
'35 days ago'
))
{
return
;
// Do not sync old
}
if
(
!
$data
[
'sender_guid'
])
{
var_dump
(
$row
);
}
$wire
=
new
\Minds\Core\Wire\Wire
();
$wire
->
setSender
(
new
\Minds\Entities\User
(
$data
[
'sender_guid'
]))
->
setReceiver
(
new
\Minds\Entities\User
(
$data
[
'receiver_guid'
]))
->
setEntity
(
\Minds\Entities\Factory
::
build
(
$data
[
'entity_guid'
]))
->
setAmount
((
string
)
$data
[
'amount'
])
->
setTimestamp
((
int
)
$row
[
'timestamp'
]
->
time
());
yield
$wire
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Core/Wire/Delegates/Plus.php
View file @
0661c86f
...
...
@@ -55,6 +55,11 @@ class Plus
$user
=
$this
->
entitiesBuilder
->
single
(
$user
->
getGuid
(),
[
'cache'
=>
false
,
]);
if
(
!
$user
)
{
return
$wire
;
}
$user
->
setPlusExpires
(
strtotime
(
'+30 days'
,
$wire
->
getTimestamp
()));
$user
->
save
();
...
...
@@ -62,4 +67,4 @@ class Plus
return
$wire
;
}
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Core/Wire/Manager.php
View file @
0661c86f
...
...
@@ -14,6 +14,7 @@ use Minds\Core\Guid;
use
Minds\Core\Util\BigNumber
;
use
Minds\Core\Wire\Exceptions\WalletNotSetupException
;
use
Minds\Core\Wire\Subscriptions\Manager
as
SubscriptionsManager
;
use
Minds\Common\Urn
;
use
Minds\Entities
;
use
Minds\Entities\User
;
...
...
@@ -328,7 +329,16 @@ class Manager
$receiver
=
new
User
(
$subscription
->
getEntity
()
->
guid
);
$amount
=
$subscription
->
getAmount
();
if
(
$subscription
->
getId
()
===
'offchain'
)
{
$id
=
$subscription
->
getId
();
if
(
strpos
(
$id
,
'urn:'
,
0
)
!==
0
)
{
error_log
(
"[wire][recurring]:
$id
was expecting a urn"
);
return
false
;
}
$urn
=
new
Urn
(
$id
);
list
(
$address
,
$sender
,
$receiver
)
=
explode
(
'-'
,
$urn
->
getNss
());
if
(
$address
===
'offchain'
)
{
$this
->
setPayload
([
'method'
=>
'offchain'
,
]);
...
...
@@ -339,14 +349,14 @@ class Manager
'to'
=>
$this
->
config
->
get
(
'blockchain'
)[
'contracts'
][
'wire'
][
'contract_address'
],
'gasLimit'
=>
BigNumber
::
_
(
200000
)
->
toHex
(
true
),
'data'
=>
$this
->
client
->
encodeContractMethod
(
'wireFromDelegate(address,address,uint256)'
,
[
$
subscription
->
getId
()
,
$
address
,
$receiver
->
getEthWallet
(),
BigNumber
::
_
(
$this
->
token
->
toTokenUnit
(
$amount
))
->
toHex
(
true
),
]),
]);
$this
->
setPayload
([
'method'
=>
'onchain'
,
'address'
=>
$
subscription
->
getId
()
,
//sender address
'address'
=>
$
address
,
//sender address
'receiver'
=>
$receiver
->
getEthWallet
(),
'txHash'
=>
$txHash
,
]);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment