Calculating the balance for near address 77yen.near - nearprotocol

When I try calculating the balance for one of the address of Near 77yen.near that does not match to the balance shown in the explorer. Can anyone please help me out here where I am missing the amount to be calculated.
The amount after my calculation is -4.02721 where as in explorer it is 0.35497.
With my calculation from all the transactions shown below total balance transferred to this address is 1066.45154 and total balance transferred from this address is -1070.47875, which becomes -4.02721. Below are the transactions that I considered for calculation. Please let me know where am I going wrong.
https://explorer.near.org/accounts/77yen.near
https://nearblocks.io/address/77yen.near
Transactions for Near address 77yen.near
Tried calculating the balance but that does not match with the balance shown in explorer.

Account is created: +0.1N [balance ~ 0.1]
Account is beneficiary of deletion: +0.89 [balance ~ 0.99]
Income Transfer: +33 [balance ~ 34]
Income Transfer: +600.66N [balance ~ 634]
Stake in validator: -634 [balance ~ 0]
Unstake + Withdraw: +636.95 [balance ~ 636.95]
Transfer out: -636.95 [balance ~ 0]
Transfer in: +432.7 [balance ~ 432.7]
Stake in validator: -432.7 [balance ~ 0]
Unstake + Withdraw: +433.53 [balance ~ 433.53]
Transfer out: -433.52941 [balance ~ 0]
Plus minus some fees, the numbers look good to me, since the balance is 0.3 at the end.
Make sure you are taking into account all the NEAR transfers. In many transactions you don't see a deposit in the top, but actually system is giving back the token not burned for gas, or the validator is sending money back to the user.

Related

Reading a folder of log files, and calculating the event durations for unique ID's

I have an air gapped system (so limited in software access) that generates usage logs daily. The logs have unique ID's for devices that I've managed to scrape in the past and pump out to a CSV, to which I would then cleanup in LibreCalc (related to this question I asked here - https://superuser.com/questions/1732415/find-next-matching-event-in-log-and-compare-timings) and get event durations for each one.
This is getting arduous as more devices are added so I wish to automate the calculation of the total durations for each device, and how many events occurred for that device. I've had some suggestions of using out/awk/sed and I'm a bit lost on how to implement it.
Log Example
message="device02 connected" event_ts=2023-01-10T09:20:21Z
message="device05 connected" event_ts=2023-01-10T09:21:31Z
message="device02 disconnected" event_ts=2023-01-10T09:21:56Z
message="device04 connected" event_ts=2023-01-10T11:12:28Z
message="device05 disconnected" event_ts=2023-01-10T15:26:36Z
message="device04 disconnected" event_ts=2023-01-10T18:23:32Z
I already have a bash script that scrapes these events from the log files in the folder and then outputs it all to a csv.
#/bin/bash
#Just a datetime stamp for the flatfile
now=$(date +”%Y%m%d”)
#Log file path, also where I define what month to scrape
LOGFILE=’local.log-202301*’
#Shows what log files are getting read
echo $LOGFILE \n
#Output line by line to csv
awk ‘(/connect/ && ORS=”\n”) || (/disconnect/ && ORS=RS) {field1_var=$1” “$2” “$3”,”; print field1_var}’ $LOGFILE > /home/user/logs/LOG_$now.csv
Ideally I'd like to keep that process so I can manually inspect the file if necessary. But ultimately I'd prefer to automate the event calculations to produce something like below:
Desired Output Example
Device Total Connection Duration Total Connections
device01 0h 0m 0s 0
device02 0h 1m 35s 1
device03 0h 0m 0s 0
device04 7h 11m 4s 1
device05 6h 5m 5s 1
Hopefully thats enough info, any help or pointers would be greatly appreciated. Thanks.
This isn't based on your script at all, since I didn't get it to produce a CSV, but anyway...
Here's an AWK script that computes the desired result for the given example log file:
function time_lapsed(from, to) {
gsub(/[^0-9 ]/, " ", from);
gsub(/[^0-9 ]/, " ", to);
return mktime(to) - mktime(from);
}
BEGIN { OFS = "\t"; }
(/ connected/) {
split($1, a, "=\"", _);
split($3, b, "=", _);
device_connected_at[a[2]] = b[2];
device_connection_count[a[2]]++;
}
(/disconnected/) {
split($1, a, "=\"", _);
split($3, b, "=", _);
device_connection_duration[a[2]]+=time_lapsed(device_connected_at[a[2]], b[2]);
}
END {
print "Device","Total Connection Duration", "Total Connections";
for (device in device_connection_duration) {
print device, strftime("%Hh %Mm %Ss", device_connection_duration[device]), device_connection_count[device];
};
}
I used it on this example log file
message="device02 connected" event_ts=2023-01-10T09:20:21Z
message="device05 connected" event_ts=2023-01-10T09:21:31Z
message="device02 disconnected" event_ts=2023-01-10T09:21:56Z
message="device04 connected" event_ts=2023-01-10T11:12:28Z
message="device06 connected" event_ts=2023-01-10T11:12:28Z
message="device05 disconnected" event_ts=2023-01-10T15:26:36Z
message="device02 connected" event_ts=2023-01-10T19:20:21Z
message="device04 disconnected" event_ts=2023-01-10T18:23:32Z
message="device02 disconnected" event_ts=2023-01-10T21:41:33Z
And it produces this output
Device Total Connection Duration Total Connections
device02 03h 22m 47s 2
device04 08h 11m 04s 1
device05 07h 05m 05s 1
You can pass this program to awk without any flags. It should just work (given you didn't mess around with field and record separators somewhere in your shell session).
Let me explain what's going on:
First we define the time_lapsed function. In that function we first convert the ISO8601 timestamps into the format that mktime can handle (YYYY MM DD HH MM SS), we simply drop the offset since it's all UTC. We then compute the difference of the Epoch timestamps that mktime returns and return that result.
Next in the BEGIN block we define the output field separator OFS to be a tab.
Then we define two rules, one for log lines when the device connected and one for when the device disconnected.
Due to the default field separator the input to these rules looks like this:
$1: message="device02
$2: connected"
$3: event_ts=2023-01-10T09:20:21Z
We don't care about $2. We use split to get the device identifier and the timestamp from $1 and $3 respectively.
In the rule for a device connecting, using the device identifier as the key, we then store when the device connected and increase the connection count for that device. We don't need to initially assign 0 because the associative arrays in awk return "" for fields that contain no record which is coerced to 0 by incrementing it.
In the rule for a device disconnecting we compute the time lapsed and add that to the total time elapsed for that device.
Note that this requires every connect to have a matching disconnect in the logs. I.e., this is very fragile, a missing connect log line will mess up the calculation of the total connection time. A missing disconnect log line with increase the connection count but not the total connection time.
In the END rule we print the desired Output header and for every entry in the associative array device_connection_duration we print the device identifier, total connection duration and total connection count.
I hope this gives you some ideas on how to solve your task.

(Micropython) Creating and comparing time objects

Using Micropython for the ESP32 microcontroller, flashed with the latest firmware at time of writing (v1.18)
I'm making an alarm (sort-of) system where I get multiple time values ("13:15" for example) from my website, and then I have to ring an alarm bell at those times.
I've done the website and I can do the ring stuff, but I don't know how to actually create time objects from the previously mentioned strings ("13:15"), and then check if any of the times inputted match the current time, the date is irrelevant.
From reading the documentation, im getting the sense that this cant be done, since ive looked through the micropython module github, and you apparently cant get datetime in micropython, and i know that in regular python my problem can be solved with datetime.
import ntptime
import time
import network
# Set esp as a wifi station
station = network.WLAN(network.STA_IF)
# Activate wifi station
station.active(True)
# Connect to wifi ap
station.connect(ssid,passwd)
while station.isconnected() == False:
print('.')
time.sleep(1)
print(station.ifconfig())
try:
print("Local time before synchronization: %s" %str(time.localtime()))
ntptime.settime()
print("Local time after synchronization: %s" %str(time.localtime()))
except:
print("Error syncing time, exiting...")
this is the shortened code from my project, with only the time parts, now comes into play the time comparison thing I don't know how to do.
Using ntptime to get time from server. I use "time.google.com", to get the time. Then, I transform it into seconds (st) to be more accurate. And set my targets hour in seconds 1 hour = 3600 s.
import utime
import ntptime
def server_time():
try:
# Ask to time.google.com server the current time.
ntptime.host = "time.google.com"
ntptime.settime()
t = time.localtime()
# print(t)
# transform tuple time 't' to seconds value. 1 hour =
st = t[3]*3600 + t[4]*60 + t[5]
return st
except:
# print('no time')
st = -1
return st
while True:
# Returns an increasing millisecond counter since the Board reset.
now = utime.ticks_ms()
# Check current time every 5000 ms (5s) without going to sleep or stop any other process.
if now >= period + 5000:
period += 5000
# call your servertime function
st = server_time()
if ((st > 0) and (st < 39600)) or (st > 82800): # Turn On 17:00 Mexico Time.
# something will be On between 17:00 - 06:00
elif ((st <82800) and (st > 39600)): # Turn Off 6:00.
# something will be Off between 06:00 - 17:00
else:
pass
After running ntptime.settime() you can do the following to retrieve the time, keep in mind this is in UTC:
rtc = machine.RTC()
hour = rtc.datetime()[4] if (rtc.datetime()[4]) > 9 else "0%s" % rtc.datetime()[4]
minute = rtc.datetime()[5] if rtc.datetime()[5] > 9 else "0%s" % rtc.datetime()[5]
The if else statement makes sure that numbers lower or equal to 9 are padded with a zero.

ValueError: Input is not valid. Should be a string, a list/tuple of strings or a list/tuple of integers

from os import listdir
from os.path import isfile, join
from datasets import load_dataset
from transformers import BertTokenizer
test_files = [join('./test/', f) for f in listdir('./test') if isfile(join('./test', f))]
dataset = load_dataset('json', data_files={"test": test_files}, cache_dir="./.cache_dir")
tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
def encode(batch):
return tokenizer.encode_plus(batch["abstract"], max_length=32, add_special_tokens=True, pad_to_max_length=True,
return_attention_mask=True, return_token_type_ids=False, return_tensors="pt")
dataset.set_transform(encode)
When I run this code, I have
ValueError: Input is not valid. Should be a string, a list/tuple of strings or a list/tuple of integers.
Instead of having a list of strings, I have a list of lists of strings. Here is the content of batch["article"]:
[['eleven politicians from 7 parties made comments in letter to a newspaper .', "said dpp alison saunders had ` damaged public confidence ' in justice .", 'ms saunders ruled lord janner unfit to stand trial over child abuse claims .', 'the cps has pursued at least 19 suspected paedophiles with dementia .'], ['an increasing number of surveys claim to reveal what makes us happiest .', 'but are these generic lists really of any use to us ?', 'janet street-porter makes her own list - of things making her unhappy !'], ["author of ` into the wild ' spoke to five rape victims in missoula , montana .", "` missoula : rape and the justice system in a college town ' was released april 21 .", "three of five victims profiled in the book sat down with abc 's nightline wednesday night .", 'kelsey belnap , allison huguet and hillary mclaughlin said they had been raped by university of montana football players .', "huguet and mclaughlin 's attacker , beau donaldson , pleaded guilty to rape in 2012 and was sentenced to 10 years .", 'belnap claimed four players gang-raped her in 2010 , but prosecutors never charged them citing lack of probable cause .', 'mr krakauer wrote book after realizing close friend was a rape victim .'], ['tesco announced a record annual loss of £ 6.38 billion yesterday .', 'drop in sales , one-off costs and pensions blamed for financial loss .', 'supermarket giant now under pressure to close 200 stores nationwide .', 'here , retail industry veterans , plus mail writers , identify what went wrong .'], ..., ['snp leader said alex salmond did not field questions over his family .', "said she was not ` moaning ' but also attacked criticism of women 's looks .", 'she made the remarks in latest programme profiling the main party leaders .', 'ms sturgeon also revealed her tv habits and recent image makeover .', 'she said she relaxed by eating steak and chips on a saturday night .']]
How could I fix this issue?

Tax rates in Magento for EU and Rest Of World

As a UK VAT registered business selling outwith the UK I have created a tax rate based on the UK VAT rate for all EU countries. Out-with the EU no VAT will be charged so am I correct in thinking I don't have to create any further rates, and that a user buying from the Rest Of World will just not have no tax rule applied so no VAT will be added nor will a tax element appear in their invoice breakdown (VAT breakdown is enabled in the config)?
An up to date CSV for EU tax rates in 2014 that works with Magento 1.9.0.1 (note that this is the current UK VAT rate of 20%). You should not be charging VAT when you ship to countries outside of the EU zone- ignore their billing address, it is where you send the items that counts. It should also be noted that Iceland, Liechtenstein, Norway and Switzerland are exempt from UK VAT.
Code,Country,State,Zip/Post Code,Rate,Zip/Post is Range,Range From,Range To,default
GB,GB,*,,20.0000,,,,VAT
AL,AL,*,,20.0000,,,,VAT
AD,AD,*,,20.0000,,,,VAT
AT,AT,*,,20.0000,,,,VAT
BY,BY,*,,20.0000,,,,VAT
BE,BE,*,,20.0000,,,,VAT
BA,BA,*,,20.0000,,,,VAT
BG,BG,*,,20.0000,,,,VAT
HR,HR,*,,20.0000,,,,VAT
CY,CY,*,,20.0000,,,,VAT
CZ,CZ,*,,20.0000,,,,VAT
DK,DK,*,,20.0000,,,,VAT
EE,EE,*,,20.0000,,,,VAT
FO,FO,*,,20.0000,,,,VAT
FI,FI,*,,20.0000,,,,VAT
FR,FR,*,,20.0000,,,,VAT
DE,DE,*,,20.0000,,,,VAT
GI,GI,*,,20.0000,,,,VAT
GR,GR,*,,20.0000,,,,VAT
HU,HU,*,,20.0000,,,,VAT
IS,IS,*,,0.0000,,,,VAT
IE,IE,*,,20.0000,,,,VAT
IT,IT,*,,20.0000,,,,VAT
LV,LV,*,,20.0000,,,,VAT
LB,LB,*,,20.0000,,,,VAT
LI,LI,*,,0.0000,,,,VAT
LT,LT,*,,20.0000,,,,VAT
LU,LU,*,,20.0000,,,,VAT
MT,MT,*,,20.0000,,,,VAT
MD,MD,*,,20.0000,,,,VAT
MC,MC,*,,20.0000,,,,VAT
ME,ME,*,,20.0000,,,,VAT
NL,NL,*,,20.0000,,,,VAT
NO,NO,*,,0.0000,,,,VAT
PL,PL,*,,20.0000,,,,VAT
PT,PT,*,,20.0000,,,,VAT
RO,RO,*,,20.0000,,,,VAT
RS,RS,*,,20.0000,,,,VAT
SK,SK,*,,20.0000,,,,VAT
SI,SI,*,,20.0000,,,,VAT
ES,ES,*,,20.0000,,,,VAT
SJ,SJ,*,,20.0000,,,,VAT
SE,SE,*,,20.0000,,,,VAT
CH,CH,*,,0.0000,,,,VAT
TR,TR,*,,20.0000,,,,VAT
UA,UA,*,,20.0000,,,,VAT
VA,VA,*,,20.0000,,,,VAT
To my understanding, both those answers are incorrect. I'm fairly certain that as UK businesses we have to charge UK VAT only to the UK and other members of the EU, and zero rate to any country outside the EU. Both answers include non-EU countries in the csv, including AL (Albania), AD (Andorra), BY (Belarus), BA (Bosnia & Herzegovina), etc, etc.
Here's my edited list, although I'm not sure about VA (Vatican City), it seems to officially not be part of the EU, so in theory zero rated, can anyone clarify? (Not that I've ever had an order from there!)
Code,Country,State,Zip/Post Code,Rate,Zip/Post is Range,Range From,Range To,default
GB,GB,*,,20.0000,,,,VAT
AT,AT,*,,20.0000,,,,VAT
BE,BE,*,,20.0000,,,,VAT
BG,BG,*,,20.0000,,,,VAT
CY,CY,*,,20.0000,,,,VAT
CZ,CZ,*,,20.0000,,,,VAT
DK,DK,*,,20.0000,,,,VAT
EE,EE,*,,20.0000,,,,VAT
FI,FI,*,,20.0000,,,,VAT
FR,FR,*,,20.0000,,,,VAT
DE,DE,*,,20.0000,,,,VAT
GI,GI,*,,20.0000,,,,VAT
GR,GR,*,,20.0000,,,,VAT
HR,HR,*,,20.0000,,,,VAT
HU,HU,*,,20.0000,,,,VAT
IE,IE,*,,20.0000,,,,VAT
IT,IT,*,,20.0000,,,,VAT
LV,LV,*,,20.0000,,,,VAT
LI,LI,*,,0.0000,,,,VAT
LT,LT,*,,20.0000,,,,VAT
LU,LU,*,,20.0000,,,,VAT
MT,MT,*,,20.0000,,,,VAT
MC,MC,*,,20.0000,,,,VAT
NL,NL,*,,20.0000,,,,VAT
NO,NO,*,,0.0000,,,,VAT
PL,PL,*,,20.0000,,,,VAT
PT,PT,*,,20.0000,,,,VAT
RO,RO,*,,20.0000,,,,VAT
SK,SK,*,,20.0000,,,,VAT
SI,SI,*,,20.0000,,,,VAT
ES,ES,*,,20.0000,,,,VAT
SE,SE,*,,20.0000,,,,VAT
CH,CH,*,,0.0000,,,,VAT
VA,VA,*,,20.0000,,,,VAT

How to set fee in raw bitcoin transaction using btcutil

According to the docs (http://godoc.org/github.com/btcsuite/btcrpcclient) the fee can be set by using
SetTxFee(fee btcutil.Amount) // hard coded0.0006 BTC
I set the fee to 0.0000016 bitcoin/kilobyte and do as follow:
ListUnspent
SetTxFee
CreateRawTransaction
SignRawTransaction
SendRawTransaction
But when i try to send transaction i get
-26: 256: absurdly-high-fee
Is there any other way to set the fee using this library?
Debug.log
ThreadRPCServer method=listunspent
ThreadRPCServer method=settxfee
ThreadRPCServer method=createrawtransaction
ThreadRPCServer method=signrawtransaction
ThreadRPCServer method=sendrawtransaction
Amounts:
amounts := map[btcutil.Address]btcutil.Amount{
destAddress: destAmount,
}
UPDATE
It seems like it tries to send whole sum of the transaction, not the amount i want it to send.
If transaction in to A is 1 BTC and i want to send 0.3 BTC to another address, how to achieve this when setting amounts?
settxfee is not for createrawtransaction command.
if you have one input with 1 BTC and you would send 0.9 BTC so remaining amount is the transaction fee.
if you don't want to set transaction fee for 0.1 BTC you could send 0.09 to change address and leave that 0.01 and it's your transaction fee.

Resources