TransferNFT script
This commit is contained in:
parent
7180ccc92e
commit
483c2476e4
@ -30,6 +30,7 @@
|
||||
<Compile Include="Bot.fs" />
|
||||
<None Include="Scripts\GetWhitelisted.fsx" />
|
||||
<None Include="Scripts\Airdrop.fsx" />
|
||||
<None Include="Scripts\TransferNFT.fsx" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\.paket\Paket.Restore.targets" />
|
||||
</Project>
|
||||
|
97
Bot/Scripts/TransferNFT.fsx
Normal file
97
Bot/Scripts/TransferNFT.fsx
Normal file
@ -0,0 +1,97 @@
|
||||
#load "/home/joe/Development/DegenzGame/.paket/load/net6.0/main.group.fsx";;
|
||||
|
||||
open Npgsql.FSharp
|
||||
open dotenv.net
|
||||
open System.IO
|
||||
open System.Diagnostics
|
||||
open System.Threading.Tasks
|
||||
|
||||
let prodEnv = DotEnv.Read(DotEnvOptions(envFilePaths = [ "./.prod.env" ]))
|
||||
let ( _ , prodConnStr )= prodEnv.TryGetValue("DATABASE_URL")
|
||||
|
||||
type NftTransfer = {
|
||||
Id : uint64
|
||||
Name : string
|
||||
NftName : string
|
||||
NftAddress : string
|
||||
UserWallet : string
|
||||
}
|
||||
|
||||
|
||||
printfn "Getting Wallet Addresses:"
|
||||
let pending =
|
||||
prodConnStr
|
||||
|> Sql.connect
|
||||
|> Sql.query """
|
||||
SELECT u.id, u.display_name, token.name, token.address, mpa.tx_wallet FROM gen_one_token token
|
||||
JOIN mint_pass_assignment mpa on token.id = mpa.token_id
|
||||
JOIN "user" u on mpa.recipient_id = u.id
|
||||
WHERE mpa.fulfilled = false AND token.locked = false AND u.id <> '815567646606229514'
|
||||
ORDER BY mpa.created_at;
|
||||
"""
|
||||
|> Sql.execute (fun reader ->
|
||||
{ Id = reader.string "id" |> uint64
|
||||
Name = reader.string "display_name"
|
||||
NftName = reader.string "name"
|
||||
NftAddress = reader.string "address"
|
||||
UserWallet = reader.string "tx_wallet" })
|
||||
|
||||
|
||||
let testSample = [ pending |> List.last ]
|
||||
|
||||
type CommandResult = {
|
||||
ExitCode: int;
|
||||
StandardOutput: string;
|
||||
StandardError: string
|
||||
}
|
||||
|
||||
let executeCommand executable args =
|
||||
async {
|
||||
let startInfo = ProcessStartInfo()
|
||||
startInfo.FileName <- executable
|
||||
|
||||
for a in args do
|
||||
startInfo.ArgumentList.Add(a)
|
||||
|
||||
startInfo.RedirectStandardOutput <- true
|
||||
startInfo.RedirectStandardError <- true
|
||||
startInfo.UseShellExecute <- false
|
||||
startInfo.CreateNoWindow <- true
|
||||
use p = new Process()
|
||||
p.StartInfo <- startInfo
|
||||
p.Start() |> ignore
|
||||
|
||||
let outTask =
|
||||
Task.WhenAll(
|
||||
[| p.StandardOutput.ReadToEndAsync()
|
||||
p.StandardError.ReadToEndAsync() |]
|
||||
)
|
||||
|
||||
do! p.WaitForExitAsync() |> Async.AwaitTask
|
||||
let! out = outTask |> Async.AwaitTask
|
||||
|
||||
return
|
||||
{ ExitCode = p.ExitCode
|
||||
StandardOutput = out.[0]
|
||||
StandardError = out.[1] }
|
||||
}
|
||||
let executeShellCommand command =
|
||||
executeCommand "/usr/bin/env" [ "-S"; "bash"; "-c"; command ]
|
||||
|
||||
|
||||
let transfer (nft : NftTransfer) =
|
||||
printfn $"Transferring {nft.NftName} to {nft.Name} "
|
||||
let result =
|
||||
$"spl-token transfer --allow-unfunded-recipient --fund-recipient {nft.NftAddress} 1 {nft.UserWallet}"
|
||||
|> executeShellCommand
|
||||
|> Async.RunSynchronously
|
||||
if result.ExitCode = 0 then
|
||||
let user = $"{nft.Id} - {nft.Name} - {nft.NftName}"
|
||||
let tx = result.StandardOutput
|
||||
File.AppendAllLines("/home/joe/Downloads/transactions", [ user ; tx ])
|
||||
else
|
||||
printfn $"{result.StandardError}"
|
||||
|
||||
|
||||
for nft in testSample do
|
||||
transfer nft
|
Loading…
x
Reference in New Issue
Block a user