#

# NOTE: This file has been royally messed up by prettier. multi line commands and side by side commands have been mangled.

# Be warned when trying to copy paste.

#

# Deploy

near login (ninja.testnet)

near login (calebgates.testnet)

near login (charlie.testnet)

near login (bobbie.testnet)

near login (alice.testnet)

//npm run build:contract:testnet

near delete tipbot.ninja.testnet ninja.testnet

near create-account tipbot.ninja.testnet --masterAccount ninja.testnet

//DEPLOY WHEREEVER THE FILE IS AT. //TODO: Change "auth_account_id" value. near
deploy tipbot.ninja.testnet --wasmFile connectors/near/contracts/tipbot.wasm \
 --initFunction 'new' \
 --initArgs '{"master_account_id": "ninja.testnet",
"linkdrop_account_id":"linkdrop.ninja.testnet",
"auth_account_id":"tipbotauth.ninja.testnet",
"tiptoken_account_id":"tiptoken.ninja.testnet" }'

near call tipbot.ninja.testnet whitelist_token '{"token_id": "near"}'
--accountId ninja.testnet

near call tipbot.ninja.testnet is_whitelisted_token '{"token_id": "near"}'
--accountId ninja.testnet

near call tipbot.ninja.testnet set_generic_tips_available
'{"generic_tips_available": true}' --accountId ninja.testnet near call
tipbot.ninja.testnet set_withdraw_available '{"withdraw_available": true}'
--accountId ninja.testnet

near call tipbot.ninja.testnet deposit '{"account_id": "calebgates.testnet"}'
--accountId calebgates.testnet --amount 5 near call tipbot.ninja.testnet
get_deposit '{"account_id": "calebgates.testnet"}' --accountId
calebgates.testnet

near add-key calebgates.testnet
ed25519:8uG3M8Kg18AGHc2rVzvMZ7SjrJbu2fGqChBBDW3L955u --contract-id
tipbot.ninja.testnet --method-names tip_known_near_account_directly_to_deposit
--allowance 30000000000

near call tipbot.ninja.testnet tip_known_near_account_directly_to_deposit
'{"receiver_account_id":"charlie.testnet", "contact":{"category":"Discord",
"value":"charlie.testnet"}, "amount":"10000000000000000000000"}' --accountId
calebgates.testnet

near call tipbot.ninja.testnet get_deposit '{"account_id": "charlie.testnet"}'
--accountId calebgates.testnet near call tipbot.ninja.testnet get_deposit
'{"account_id": "calebgates.testnet"}' --accountId calebgates.testnet

//Create a function access key: //1. Create a public private key pair. This
needs to be HIDDEN as it has access to every account if authorized. // The
reason this is a new pair is so that a server can generate it without needing
any near. its not a user account. it cannot spend money so it doesnt actually
need any money or to be stored on the block chain. // Every account can
authroize the same public key for which the private key is stored on the collab
land server. near generate-key // Output: Key pair with
ed25519:CyN1GLgRARvnpPnxfN2Gp8QRpVSaMPfiCt4cJxwwdEC8 public key for an account
"b1e0d4d892170ff4f87cadd3c2e420d085b7305f444f8b88e880983d9ffedb59"

near add-key calebgates.testnet
ed25519:CyN1GLgRARvnpPnxfN2Gp8QRpVSaMPfiCt4cJxwwdEC8 --contract-id
tipbot.ninja.testnet --method-names
on_get_contact_owner_on_tip_contact_receiver_to_deposit --allowance 30000000000
near add-key calebgates.testnet
ed25519:8uG3M8Kg18AGHc2rVzvMZ7SjrJbu2fGqChBBDW3L955u --contract-id
tipbot.ninja.testnet --method-names
on_get_contact_owner_on_tip_contact_receiver_to_deposit --allowance 30000000000
//This is for the dev account: "dev-1633104319542-95501434147225" which I dont
rememvber creating but it's in
"~/near-credentials/testnet/"dev-1633104319542-95501434147225"

//2. Call function on users behalf //Also need to debug this and then make sure
its secure and only this authorized account can transfer their money. and see
who shows up as the predecesor

near call tipbot.ninja.testnet
on_get_contact_owner_on_tip_contact_receiver_to_deposit
'{"receiver_account_id":"charlie.testnet", "contact":{"category":"Discord",
"value":"charlie.testnet"}, "amount_wrapped":"10000000000000000000000"}'
--accountId dev-1633104319542-95501434147225 --helperAccount calebgates.testnet

//3. remove the dev-xxxx-xxxx account from the deploy script or at least change
it.

near call tipbot.ninja.testnet
on_get_contact_owner_on_tip_contact_receiver_to_deposit
'{"receiver_account_id":"charlie.testnet", "contact":{"category":"Discord",
"value":"charlie.testnet"}, "amount_wrapped":"10000000000000000000000"}'
--accountId ed25519:CyN1GLgRARvnpPnxfN2Gp8QRpVSaMPfiCt4cJxwwdEC8

Helpful links: https://docs.near.org/docs/tools/near-cli
https://docs.near.org/docs/develop/front-end/introduction#authentication
https://nomicon.io/DataStructures/AccessKey.html
https://nomicon.io/Proposals/0005-access-keys.html
https://www.youtube.com/watch?v=ganXZ0Iw1C8

curl -X POST https://rpc.testnet.near.org -H 'content-type: application/json'
--data \
 '{ "jsonrpc": "2.0", "id": "dontcare", "method": "query", "params": {
"request_type": "view_access_key_list", "finality": "final", "account_id":
"calebgates.testnet" } }'

(Log [tipbot.ninja.testnet]: @calebgates.testnet deposited
100000000000000000000000 of "near")

near call tipbot.ninja.testnet deposit '{"account_id": "charlie.testnet"}'
--accountId charlie.testnet --amount 0.2

near call tipbot.ninja.testnet withdraw '{"account_id": "calebgates.testnet"}'
--accountId calebgates.testnet (Log [tipbot.ninja.testnet]: @calebgates.testnet
withdrew 100000000000000000000000 of "near" from internal deposit)

Next: Deposit funds and tip. Then grant access to another account and all them
to tip for you.

near call tipbot.ninja.testnet deposit '{"account_id": "calebgates.testnet"}'
--accountId calebgates.testnet --amount 0.1 (Log [tipbot.ninja.testnet]:
@calebgates.testnet deposited 100000000000000000000000 of "near")

near call tipbot.ninja.testnet get_deposit '{"account_id":
"calebgates.testnet"}' --accountId calebgates.testnet
('200000000000000000000000')

near state calebgates.testnet (Shows how much near I have, can see that I now
have .1 less)

near state charlie.testnet (formattedAmount: '150.0526024336375')

#### Cannot figure out how to tip because tip_transfer seems to be semi private.

## near call tipbot.ninja.testnet tip_transfer '{"sender_account_id":"calebgates.testnet", "receiver_account_id":"charlie.testnet", "contact": "calebgates.testnet", "deposit":""}' --accountId calebgates.testnet

# I dont like how this is a payable function. I want to have a function that collab land can call.

# Testing it out though:

# \***\*\*\*\*** Why pay with attached tokens if I have already deposited funds. is there a way to pay with deposited tokens? **\*\*\*\***

near call tipbot.ninja.testnet tip_with_attached_tokens
'{"sender_account_id":"calebgates.testnet",
"receiver_account_id":"charlie.testnet", "contact": "calebgates.testnet"}'
--accountId calebgates.testnet --amount 0.1 (FAILED: Expected Struct Contact)

near call tipbot.ninja.testnet tip_with_attached_tokens
'{"sender_account_id":"calebgates.testnet",
"receiver_account_id":"charlie.testnet", "contact": {"category":"Discord",
"value":"charlie.testnet"}}' --accountId calebgates.testnet --amount 0.1

### IGNORE: near call tipbot.ninja.testnet tip_with_attached_tokens '{"sender_account_id":"calebgates.testnet", "receiver_account_id":"charlie.testnet", "contact": {"category":"Discord", "value":"charlie.testnet", "account_id":""}}' --accountId calebgates.testnet --amount 0.1

# TODO: Get tips once I figure out how to send. Also I feel like you could do this with any account.

near call tipbot.ninja.testnet get_tips '{"account_id": "charlie.testnet"}'
--accountId calebgates.testnet ([ { contact: { category: 'Discord', value:
'charlie.testnet', account_id: null }, amount: 1e+23 } ] ) near state
charlie.testnet (formattedAmount: '150.0526024336375')

near call tipbot.ninja.testnet withdraw --accountId charlie.testnet
#XXXX(FAILURE: Missing Deposit - But I have a tip available so how do I withdraw
my tips?)

near call tipbot.ninja.testnet withdraw_tip_for_current_account
'{"contact":{"category":"Discord",
"value":"charlie.testnet"},"balance_to_withdraw":"0.1"}' --accountId
calebgates.testnet #XXXX(FAILURE FUNCTION NOT PUBLIC)

Failed when --accountID did not match the value:charlie.testnet near call
tipbot.ninja.testnet withdraw_tip '{"contact":{"category":"Discord",
"value":"charlie.testnet"}}' --accountId charlie.testnet

## TO TRY: Can I use a contact category that has not been defined yet? Or can I edit the contract to add a category like "near account"

## NOT VERY HAPPY SO FAR I CANNOT TIP WITH MY DEPOSIT, only with attached...

##!!! Should the contract be calling this? It's not payable? && how do I grant
the function an access key? it doesnt say it's #[payable] so I believe the
contract coudl call without me siging if I gave rights..?

## TODO

## TODO

near call tipbot.ninja.testnet withdraw_tip '{"contact":{"category":"Discord",
"value":"charlie.testnet"}}' --allowance 30000000000 --accountId charlie.testnet

###

## TODO

## May want to use "send_tip_to_telegram" and pass to discord id, however that sends from the predecessor_account_id() which is the bot even though the bot can send from your account?...

##### CHALLENGE: HOW DO YOU USE THE BOT TO SEND MONEY WITHOUT SIGNING TRANSACTIONS EVERY TIME, or having to initialize the transaction...

todo: Check calebgates.testnet's balance. Then send this call vv Then if works
check charlies balance.

## DOESNT WORK

near call tipbot.ninja.testnet on_get_contact_owner_on_tip_contact_to_deposit
'{"sender_account_id":"calebgates.testnet", "contact":{"category":"Discord",
"value":"charlie.testnet"}, "amount":"100000000000000000000000"}' --accountId
charlie.testnet

# TEST THIS NEW FUNCTION. May fail because tips can only be sent by bot. Should probably remove that check. Doesnt make sense

near call tipbot.ninja.testnet
on_get_contact_owner_on_tip_contact_receiver_to_deposit
'{"receiver_account_id":"charlie.testnet", "contact":{"category":"Discord",
"value":"charlie.testnet"}, "amount":"100000000000000000000000"}' --accountId
calebgates.testnet near call tipbot.ninja.testnet
on_get_contact_owner_on_tip_contact_receiver_to_deposit
'{"receiver_account_id":"charlie.testnet", "contact":{"category":"Discord",
"value":"charlie.testnet"}, "amount_wrapped":"100000000000000000000000"}'
--accountId calebgates.testnet

//This is the url for making an offer on mintbase:
https://wallet.near.org/sign?transactions=CgAAAGVuZGVyLm5lYXIAG%2Bx7RvpKpph3zYSiVmz%2B7KskOFAYUhBO03gmVemmkVUD%2BFxKBywAABUAAABtYXJrZXQubWludGJhc2UxLm5lYXJrCwkk%2FkbyNKRSYVx5sOlPVh2rYKCzj22GZfSJbGRxbwEAAAACCgAAAG1ha2Vfb2ZmZXJlAAAAeyJ0b2tlbl9rZXkiOiIyMjQ6bmVhcmNvbi5taW50YmFzZTEubmVhciIsInByaWNlIjoiMzUwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMCIsInRpbWVvdXQiOnsiSG91cnMiOjI0fX0AgPQg5rUAAAAAgLM%2FzVNhJ%2BUCAAAAAAA%3D&callbackUrl=https%3A%2F%2Fwww.mintbase.io%2Fthing%2Fm8nLnU9sKhXWBJa5WyL0sbr_b1qFuy1sNARyEOYeeDA%3Anearcon.mintbase1.near%2Fauction%3FlistId%3D55%3Anearcon.mintbase1.near

//How do I grant function call privleges to another account (aka the contract
itself... (no) ... to the collab land account? )

near add-key calebgates.testnet
ed25519:69xXmZJyExaWEpyGcBxSoSFFJ7sNvRXysFAsYaXEpsPC --contract-id
tipbot.ninja.testnet --method-names tip_known_near_account_directly_to_deposit
get_deposit --allowance 30000000000

near add-key calebgates.testnet
ed25519:69xXmZJyExaWEpyGcBxSoSFFJ7sNvRXysFAsYaXEpsPC --contract-id
tipbot.ninja.testnet --method-names tip_known_near_account_directly_to_deposit
get_deposit --allowance 30000000000 //Copy function access key to
~/.near-credentials/testnet/calebgates.testnet.json near call
tipbot.ninja.testnet get_deposit '{"account_id": "calebgates.testnet"}'
--accountId calebgates.testnet

near add-key calebgates.testnet
ed25519:GzSfJXAYrstUQWCaah97S8TkZeoZkpRymxDv6XQTRk62 --contract-id
tipbot.ninja.testnet --method-names tip_known_near_account_directly_to_deposit
get_deposit --allowance 30000000000

ed25519:FNLdbtPCh326hC61CLpuLaBhhfHPEwn1xVUEAkrUx7fH near add-key
calebgates.testnet ed25519:FNLdbtPCh326hC61CLpuLaBhhfHPEwn1xVUEAkrUx7fH
--contract-id tipbot.ninja.testnet --method-names
tip_known_near_account_directly_to_deposit get_deposit --allowance 30000000000

So this generated a valid key and added it to a file. I think that me copying
the key changes it some how NEAR_ENV=testnet near generate-key test-acnt.testnet

GENERATING NEW KEY PAIRS: **\* Also this is not the private key Key pair with
ed25519:69xXmZJyExaWEpyGcBxSoSFFJ7sNvRXysFAsYaXEpsPC public key for an account
"4c95de9fcb960d307ffbac7032d0fa026ce7befe902f565705477d805ae36db7" The second
value is the account name. Key pair with
ed25519:FNLdbtPCh326hC61CLpuLaBhhfHPEwn1xVUEAkrUx7fH public key for an account
"test-acnt.testnet" ** I find the private key by editing this file vim
4c95de9fcb960d307ffbac7032d0fa026ce7befe902f565705477d805ae36db7.json \*\* This
is the private key
{"account_id":"4c95de9fcb960d307ffbac7032d0fa026ce7befe902f565705477d805ae36db7","public_key":"ed25519:69xXmZJyExaWEpyGcBxSoSFFJ7sNvRXysFAsYaXEpsPC","private_key":"ed25519:4NaSXs2RFQrgFQvU8t8NZoSpe6bwdi95C3nu2P4nt6s2jdJbULrmQyfs3ETL4dZ76GFr85FjrpMZLqjRVS6TWAqC"}
If I want to save to a specific account I need to tell it what account to
generate the key for. aka NEAR_ENV=testnet near generate-key test-acnt.testnet

Let's see if I am somehow using the wrong key in the code. Also let's see if I
can hard code in this private key after adding it to calebgates.testnet and see
if I can get it to run instead of generating a key from an eth address (comment
that out for now.)

Add this new key pair, test and hard code into my job for now

cp og_calebgates.testnet.json calebgates.testnet.json near add-key
calebgates.testnet ed25519:69xXmZJyExaWEpyGcBxSoSFFJ7sNvRXysFAsYaXEpsPC
--contract-id tipbot.ninja.testnet --method-names
tip_known_near_account_directly_to_deposit get_deposit --allowance 30000000000
cp 4c95de9fcb960d307ffbac7032d0fa026ce7befe902f565705477d805ae36db7.json
calebgates.testnet.json near call tipbot.ninja.testnet get_deposit
'{"account_id": "calebgates.testnet"}' --accountId calebgates.testnet

works. Ok next run this job and see what happens

1100000000000000000000000 10000000000000000000000000000000000000000000000

cp og_calebgates.testnet.json calebgates.testnet.json export NEAR_ENV=testnet

///// WHITE LIST YO TOKEN & TRY AND DEPOSIT

near call tipbot.ninja.testnet whitelist_token '{"token_id":
"yo.tokens.testnet"}' --accountId ninja.testnet

near call tipbot.ninja.testnet tip_known_near_account_directly_to_deposit
'{"receiver_account_id":"calebgates.testnet", "contact":{"category":"Discord",
"value":"calebgates.testnet"}, "amount":"21000000000000000000000",
"token_id":"yo.tokens.testnet"}' --accountId calebgates.testnet

near call tipbot.ninja.testnet deposit '{"account_id": "calebgates.testnet",
"token_id":"yo.tokens.testnet", "amount":"10999000000000000000000000"}'
--accountId calebgates.testnet

///// Attempt tipping users discord id

near call tipbot.ninja.testnet send_tip_to_telegram_with_auth
'{"telegram_account":897576644871610398, "amount":"21000000000000000000000"}'
--accountId calebgates.testnet --gas 2428153537136000000000
