11import * as smartweave from "smartweave" ;
2- import shell from "shelljs"
3- import { VERSION } from "../helper.js"
2+ import shell from "shelljs" ;
3+ import pkg from "bignumber.js" ;
4+ const { BigNumber } = pkg ;
5+
6+ import { VERSION } from "../helper.js" ;
7+ import { newProgressBar } from "./util.js" ;
48
59// prettier-ignore
610const argitRemoteURIRegex = '^gitopia:\/\/([a-zA-Z0-9-_]{43})\/([A-Za-z0-9_.-]*)'
7- const contractId = "UvjBvJUy8pOMR_lf85tBDaJD0jF85G5Ayj1p2h7yols " ;
11+ const contractId = "1ljLAR55OhtenU0iDWkLGT6jF4ApxeQd5P0gXNyNJXg " ;
812
913export function parseArgitRemoteURI ( remoteURI ) {
1014 const matchGroups = remoteURI . match ( argitRemoteURIRegex ) ;
@@ -27,19 +31,21 @@ export async function makeUpdateRefDataItem(
2731 { name : "Version" , value : "0.0.2" } ,
2832 { name : "Ref" , value : ref } ,
2933 { name : "Type" , value : "update-ref" } ,
30- { name : "App-Name" , value : "gitopia " } ,
34+ { name : "App-Name" , value : "Gitopia " } ,
3135 {
3236 name : "Unix-Time" ,
3337 value : Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( ) ,
3438 } ,
35- { name : "Content-Type" , value : "text/plain " } ,
39+ { name : "Content-Type" , value : "application/json " } ,
3640 ] ;
3741
38- const numCommits = shell . exec ( `git rev-list --count ${ ref } ` , { silent : true } ) . stdout . trim ( ) ;
42+ const numCommits = shell
43+ . exec ( `git rev-list --count ${ ref } ` , { silent : true } )
44+ . stdout . trim ( ) ;
3945 const obj = {
4046 oid,
41- numCommits
42- }
47+ numCommits,
48+ } ;
4349 const data = JSON . stringify ( obj ) ;
4450
4551 const item = await arData . createData ( { data, tags } , wallet ) ;
@@ -59,7 +65,7 @@ export const makeDataItem = async (
5965 { name : "Version" , value : "0.0.2" } ,
6066 { name : "Repo" , value : repoName } ,
6167 { name : "Type" , value : "git-object" } ,
62- { name : "App-Name" , value : "gitopia " } ,
68+ { name : "App-Name" , value : "Gitopia " } ,
6369 {
6470 name : "Unix-Time" ,
6571 value : Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( ) ,
@@ -83,43 +89,63 @@ export const postBundledTransaction = async (
8389 const data = JSON . stringify ( bundle ) ;
8490 const tx = await arweave . createTransaction ( { data } , wallet ) ;
8591 tx . addTag ( "Repo" , repoName ) ;
86- tx . addTag ( "Version" , "0.0.2" )
92+ tx . addTag ( "Version" , "0.0.2" ) ;
8793 tx . addTag ( "Type" , "git-objects-bundle" ) ;
88- tx . addTag ( "App-Name" , "gitopia " ) ;
94+ tx . addTag ( "App-Name" , "Gitopia " ) ;
8995 tx . addTag ( "Bundle-Format" , "json" ) ;
9096 tx . addTag ( "Bundle-Version" , "1.0.0" ) ;
9197 tx . addTag ( "Content-Type" , "application/json" ) ;
9298 tx . addTag ( "Helper" , VERSION ) ;
99+ tx . addTag ( "Unix-Time" , Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( ) ) ;
93100
94101 // Push triggered from gitopia mirror action
95102 if ( process . env . GITHUB_SHA ) {
96- tx . addTag ( "Origin" , "gitopia-mirror-action" )
103+ tx . addTag ( "Origin" , "gitopia-mirror-action" ) ;
97104 } else {
98- tx . addTag ( "Origin" , "git-remote-gitopia" )
105+ tx . addTag ( "Origin" , "git-remote-gitopia" ) ;
99106 }
100107
101108 await arweave . transactions . sign ( tx , wallet ) ;
102109 const uploader = await arweave . transactions . getUploader ( tx ) ;
103110
111+ const bar = newProgressBar ( ) ;
112+ bar . start ( uploader . totalChunks , 0 ) ;
113+
104114 while ( ! uploader . isComplete ) {
105115 await uploader . uploadChunk ( ) ;
106- console . error (
107- `${ uploader . pctComplete } % complete, ${ uploader . uploadedChunks } /${ uploader . totalChunks } `
108- ) ;
116+ bar . update ( uploader . uploadedChunks ) ;
109117 }
110118
119+ bar . stop ( ) ;
120+
111121 // Send fee to PST holders
112- const contractState = await smartweave . default . readContract ( arweave , contractId ) ;
113- const holder = smartweave . default . selectWeightedPstHolder ( contractState . balances ) ;
114- // send a fee. You should inform the user about this fee and amount.
122+ const contractState = await smartweave . default . readContract (
123+ arweave ,
124+ contractId
125+ ) ;
126+ const holder = smartweave . default . selectWeightedPstHolder (
127+ contractState . balances
128+ ) ;
129+
130+ // PST Fee
131+ const txFee = new BigNumber ( tx . reward ) ;
132+ const pstFee = txFee . multipliedBy ( 0.1 ) ;
133+
134+ const quantity = pstFee . isGreaterThan (
135+ BigNumber ( arweave . ar . arToWinston ( "0.01" ) )
136+ )
137+ ? pstFee . toFixed ( 0 )
138+ : arweave . ar . arToWinston ( "0.01" ) ;
139+
115140 const pstTx = await arweave . createTransaction (
116- { target : holder , quantity : arweave . ar . arToWinston ( "0.01" ) } ,
141+ { target : holder , quantity } ,
117142 wallet
118143 ) ;
119- pstTx . addTag ( "Bundle-TxID " , tx . id )
144+ pstTx . addTag ( "Bundle-Txid " , tx . id ) ;
120145 pstTx . addTag ( "Repo" , repoName ) ;
121146 pstTx . addTag ( "Version" , "0.0.2" ) ;
122- pstTx . addTag ( "App-Name" , "gitopia" ) ;
147+ pstTx . addTag ( "App-Name" , "Gitopia" ) ;
148+ pstTx . addTag ( "Unix-Time" , Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( ) ) ;
123149
124150 await arweave . transactions . sign ( pstTx , wallet ) ;
125151 await arweave . transactions . post ( pstTx ) ;
0 commit comments