Issue in creating a raw bitcoin transaction(single input and single output) - bitcoin

When signing a transaction,I have copied the scriptPubKey from previous referenced transaction (for script field in input) and appended the hash-type.
Then in the original transaction,I have replaced the script with scriptSig and removed the hash-type.
Raw Transaction.
But,when I check the transaction is coinb.in,it says that the transaction is not signed.
The code I'm using to generate is inspired from Ken Shirriff's blog and Shlomi's video on youtube
My version of the code can be found here
Snippet which populates the transaction is here:
def get_real_transaction(self,account):
sigscript = self.generate_sig_script(account)
self.real_transaction = ""
self.real_transaction = (
self.version
+ self.txn_inputs_count
+ self.txn_inputs[0]["output_hash"]
+ self.txn_inputs[0]["output_index"]
+ self.txn_inputs[0]["sigScriptBytes"]
+ self.txn_inputs[0]["sigScript"]
+ self.txn_inputs[0]["sequence"]
+ self.txn_outputs_count
+ self.txn_outputs[0]["value"]
+ self.txn_outputs[0]["scriptPubKeyBytes"]
+ self.txn_outputs[0]["scriptPubKey"]
+ self.locktime
)
return self.real_transaction
Entire transaction.py is here
Any guidance/hints will be extremely helpful.

Related

Dropbox - Automatic Refresh token Using oauth 2.0 with offlineaccess

I now: the automatic token refreshing is not a new topic.
This is the use case that generate my problem: let's say that we want extract data from Dropbox. Below you can find the code: for the first time works perfectly: in fact 1) the user goes to the generated link; 2) after allow the app coping and pasting the authorization code in the input box.
The problem arise when some hours after the user wants to do the same operation. How to avoid or by-pass the newly generation of authorization code and go straight to the operation?enter code here
As you can see in the code in a short period is possible reinject the auth code inside the code (commented in the code). But after 1 hour or more this is not loger possible.
Any help is welcome.
#!/usr/bin/env python3
import dropbox
from dropbox import DropboxOAuth2FlowNoRedirect
'''
Populate your app key in order to run this locally
'''
APP_KEY = ""
auth_flow = DropboxOAuth2FlowNoRedirect(APP_KEY, use_pkce=True, token_access_type='offline')
target='/DVR/DVR/'
authorize_url = auth_flow.start()
print("1. Go to: " + authorize_url)
print("2. Click \"Allow\" (you might have to log in first).")
print("3. Copy the authorization code.")
auth_code = input("Enter the authorization code here: ").strip()
#auth_code="3NIcPps_UxAAAAAAAAAEin1sp5jUjrErQ6787_RUbJU"
try:
oauth_result = auth_flow.finish(auth_code)
except Exception as e:
print('Error: %s' % (e,))
exit(1)
with dropbox.Dropbox(oauth2_refresh_token=oauth_result.refresh_token, app_key=APP_KEY) as dbx:
dbx.users_get_current_account()
print("Successfully set up client!")
for entry in dbx.files_list_folder(target).entries:
print(entry.name)
def dropbox_list_files(path):
try:
files = dbx.files_list_folder(path).entries
files_list = []
for file in files:
if isinstance(file, dropbox.files.FileMetadata):
metadata = {
'name': file.name,
'path_display': file.path_display,
'client_modified': file.client_modified,
'server_modified': file.server_modified
}
files_list.append(metadata)
df = pd.DataFrame.from_records(files_list)
return df.sort_values(by='server_modified', ascending=False)
except Exception as e:
print('Error getting list of files from Dropbox: ' + str(e))
#function to get the list of files in a folder
def create_links(target, csvfile):
filesList = []
print("creating links for folder " + target)
files = dbx.files_list_folder('/'+target)
filesList.extend(files.entries)
print(len(files.entries))
while(files.has_more == True) :
files = dbx.files_list_folder_continue(files.cursor)
filesList.extend(files.entries)
print(len(files.entries))
for file in filesList :
if (isinstance(file, dropbox.files.FileMetadata)) :
filename = file.name + ',' + file.path_display + ',' + str(file.size) + ','
link_data = dbx.sharing_create_shared_link(file.path_lower)
filename += link_data.url + '\n'
csvfile.write(filename)
print(file.name)
else :
create_links(target+'/'+file.name, csvfile)
#create links for all files in the folder belgeler
create_links(target, open('links.csv', 'w', encoding='utf-8'))
listing = dbx.files_list_folder(target)
#todo: add implementation for files_list_folder_continue
for entry in listing.entries:
if entry.name.endswith(".pdf"):
# note: this simple implementation only works for files in the root of the folder
res = dbx.sharing_get_shared_links(
target + entry.name)
#f.write(res.content)
print('\r', res)

How can fixe the probel of saving gganime file that is related to using the old API?

My code is following:
p <- ggplot() +
geom_sf(data = world, size = .1) +
geom_sf(aes(fill = SupDem), data = plotdata) +
scale_fill_viridis_c(option = "plasma") +
ggtitle("Democratic Support - {closest_state}") +
transition_states(Year)
anim_save("SupforDemAnim.gif", p)
The error:
Error: It appears that you are trying to use the old API, which has been deprecated.
Please update your code to the new API or install the old version of gganimate
from https://github.com/thomasp85/gganimate/releases/tag/v0.1.1

codename one push notification meet error "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure"

We have a web project which is always working fine, it just using codename one push api to push notification to our devices, but it suddenly get the following error:
javax.net.ssl.SSLHandshakeException: Received fatal alert:
handshake_failure
Below is the core code (same with codenamoe one demo)
HttpURLConnection connection = (HttpURLConnection)new URL("https://push.codenameone.com/push/push").openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
String cert = ITUNES_DEVELOPMENT_PUSH_CERT;
String pass = ITUNES_DEVELOPMENT_PUSH_CERT_PASSWORD;
if(ITUNES_PRODUCTION_PUSH) {
cert = ITUNES_PRODUCTION_PUSH_CERT;
pass = ITUNES_PRODUCTION_PUSH_CERT_PASSWORD;
}
String query = "token=" + PUSH_TOKEN +
"&device=" + URLEncoder.encode(deviceId1, "UTF-8") +
"&device=" + URLEncoder.encode(deviceId2, "UTF-8") +
"&device=" + URLEncoder.encode(deviceId3, "UTF-8") +
"&type=1" +
"&auth=" + URLEncoder.encode(FCM_SERVER_API_KEY, "UTF-8") +
"&certPassword=" + URLEncoder.encode(pass, "UTF-8") +
"&cert=" + URLEncoder.encode(cert, "UTF-8") +
"&body=" + URLEncoder.encode(MESSAGE_BODY, "UTF-8") +
"&production=" + ITUNES_PRODUCTION_PUSH +
"&sid=" + URLEncoder.encode(WNS_SID, "UTF-8") +
"&client_secret=" + URLEncoder.encode(WNS_CLIENT_SECRET, "UTF-8");
try (OutputStream output = connection.getOutputStream()) {
output.write(query.getBytes("UTF-8"));
}
int c = connection.getResponseCode();
// read response JSON
I directly run the code in unit test, it works well.
But when I call the function from project (such as a button from webpage), the error happened.
I tried several way to solve it but still can not work, please give me some suggestion to fix the issue. Thank you!
This generally happens if the certificate is invalid or out of date etc. It can happen if your connection. I just verified our SSL certificate on the push servers and it's valid (generated by cloudflare) so I suggest checking the routes to the server and your version of Java. You should have Java 8 or newer with a recent enough minor update version.

Convert Date field while retreiving from Sharepoint list in client object

I am creating a windows forms which loads list items from sharepoint client object model.
I am having issue with Date field which is giving +1 day or -1 day i.e if i have entered date as 5/5/2014 it gives 5/6/2014 or sometimes 5/4/2014.
_query.ViewXml = "<View><Query><Where>" +
"<And><Geq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conStartDate + "</Value></Geq>" +
"<And><Leq><FieldRef Name='Effort_x0020_Date'/><Value IncludeTimeValue='FALSE' Type='DateTime'>" + conEndDate + "</Value></Leq>" +
"<Eq><FieldRef Name='Author' LookupId=’TRUE’/><Value Type=’Text’>" + UserID + "</Value></Eq></And></And></Where>" +
"<GroupBy Collapse='TRUE'><FieldRef Name='WBS_x0020_Code'/></GroupBy></Query><RowLimit>25</RowLimit></View>";
SP.ListItemCollection _listitems = list.GetItems(_query);
clientcontext.ExecuteQuery();
After executing this if i use the below code it works properly but takes lot of time.
foreach(ListItem item in _listitems) {
DateTime start = ((DateTime) item["Effort_x0020_Date"]);
ClientResult < string > result = Utility.FormatDateTime(clientcontext, clientcontext.Web, start, DateTimeFormat.DateTime);
clientcontext.ExecuteQuery();
DateTime rightStart = Convert.ToDateTime(result.Value, new CultureInfo((int) web.Language));
//item["Effort_x0020_Date"] = rightStart;
}
Somehow i want an alternate way by which this could be done faster so that everytime connecting to sharepoint is avoided.
I resolved the issue by putting
_query.DatesInUtc=false.
It worked!!

Export custom formatted expressions from Mathematica

How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting, that is, 72 columns and a continuation marker on the sixth column?
I am using Mathematica to generate large and complex analytic expressions, which I then need to insert into pre-existing Fortran77 code. I have everything working correctly in the front end of Mathematica with FortranForm[] and
SetOptions[$Output, PageWidth -> 72]
However, I can't figure out how to get Mathematica to output correctly to a text file. I want something like this:
MM11 = mH1**2 + (g2**2*v1**2)/2. -
- (g2**2*(v1**2/2. -
- ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
- (v2*Cos(phi2) + (0,1)*v2*Sin(phi2)))/2.))/2.
...
but get either this:
MM11 = FortranForm[mH1^2 + (g2^2*v1^2)/2 - ...
or this:
MM11 = mH1**2 + (g2**2*v1**2)/2. - (g2**2*
(v1**2/2. - ((v2*Cos(phi2) - (0,1)*v2*Sin(phi2))*
...
This is a job for the surprisingly little-known Splice function. First, you make a template file, with the extension ".mf", like so:
file = "test.mf";
out = OpenWrite[file];
WriteString[out, "MH1 = <* form *>"];
Close[out];
Now when you use Splice, Mathematica will automatically replace everything between the <* and *> delimiters with its evaluated form. So if you set
form = 4 + b9^2 + c1^5 + c4^5 + h10^4 + j2 + k10^4 + p10^4 + q5^5 +
q8 + s3^3 + s7^2 + t6^3 + u3^2 + u9^3 + x8^4 + z2^3;
and call
Splice["test.mf", PageWidth -> 72];
which will automatically infer you want FortranForm output from the file extension, and which allows you to set PageWidth as an option, you will get a pretty decent result in the automatically generated file "test.f" (note the new extension):
MH1 = 4 + b9**2 + c1**5 + c4**5 + h10**4 + j2 + k10**4 + p10**4 +
- q5**5 + q8 + s3**3 + s7**2 + t6**3 + u3**2 + u9**3 + x8**4 +
- z2**3
Look at the docs for Splice for more options (changing the name of the output file and the like).