1+ import Arweave from "arweave" ;
12import * as smartweave from "smartweave" ;
23import shell from "shelljs" ;
34import pkg from "bignumber.js" ;
@@ -6,13 +7,21 @@ const { BigNumber } = pkg;
67import { VERSION } from "../helper.js" ;
78import { newProgressBar } from "./util.js" ;
89
10+ export const arweave = Arweave . init ( {
11+ host : "arweave.net" , // Arweave Gateway
12+ //host: 'arweave.dev', // Arweave Dev Gateway
13+ port : 443 ,
14+ protocol : "https" ,
15+ timeout : 600000 ,
16+ } ) ;
17+
918// prettier-ignore
1019const argitRemoteURIRegex = '^gitopia:\/\/([a-zA-Z0-9-_]{43})\/([A-Za-z0-9_.-]*)'
1120const contractId = "1ljLAR55OhtenU0iDWkLGT6jF4ApxeQd5P0gXNyNJXg" ;
1221
1322const sleep = async ( ms ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
1423
15- const getStatus = async ( arweave , txid ) =>
24+ const getStatus = async ( txid ) =>
1625 ( await arweave . transactions . getStatus ( txid ) ) . status ;
1726
1827export function parseArgitRemoteURI ( remoteURI ) {
@@ -24,7 +33,6 @@ export function parseArgitRemoteURI(remoteURI) {
2433}
2534
2635export async function makeUpdateRefTx (
27- arweave ,
2836 wallet ,
2937 remoteURI ,
3038 ref ,
@@ -93,7 +101,7 @@ export const makeDataItem = async (
93101 return await arData . sign ( item , wallet ) ;
94102} ;
95103
96- export const makeBundledDataTx = async ( arweave , wallet , remoteURI , bundle ) => {
104+ export const makeBundledDataTx = async ( wallet , remoteURI , bundle ) => {
97105 const { repoName } = parseArgitRemoteURI ( remoteURI ) ;
98106 const data = JSON . stringify ( bundle ) ;
99107 const tx = await arweave . createTransaction ( { data } , wallet ) ;
@@ -110,7 +118,7 @@ export const makeBundledDataTx = async (arweave, wallet, remoteURI, bundle) => {
110118 return tx ;
111119} ;
112120
113- export const postTransaction = async ( arweave , tx ) => {
121+ export const postTransaction = async ( tx ) => {
114122 const uploader = await arweave . transactions . getUploader ( tx ) ;
115123
116124 const bar = newProgressBar ( ) ;
@@ -124,14 +132,14 @@ export const postTransaction = async (arweave, tx) => {
124132 bar . stop ( ) ;
125133} ;
126134
127- export const waitTxPropogation = async ( arweave , tx ) => {
128- let status = await getStatus ( arweave , tx . id ) ;
135+ export const waitTxPropogation = async ( tx ) => {
136+ let status = await getStatus ( tx . id ) ;
129137
130138 let wait = 6 ;
131139 while ( status === 404 && wait -- ) {
132140 await sleep ( 5000 ) ;
133141 try {
134- status = await getStatus ( arweave , tx . id ) ;
142+ status = await getStatus ( tx . id ) ;
135143 } catch ( err ) {
136144 wait ++ ;
137145 status = 404 ;
@@ -152,7 +160,7 @@ export const waitTxPropogation = async (arweave, tx) => {
152160 do {
153161 await sleep ( 40000 ) ; //40 secs
154162 try {
155- status = await getStatus ( arweave , tx . id ) ;
163+ status = await getStatus ( tx . id ) ;
156164 } catch ( err ) {
157165 tries ++ ;
158166 status = 404 ;
@@ -167,7 +175,6 @@ export const waitTxPropogation = async (arweave, tx) => {
167175} ;
168176
169177export const sendPSTFee = async (
170- arweave ,
171178 wallet ,
172179 remoteURI ,
173180 transactionsInfo ,
@@ -197,22 +204,16 @@ export const sendPSTFee = async (
197204 ? pstFee . toFixed ( 0 )
198205 : arweave . ar . arToWinston ( "0.01" ) ;
199206
200- let pstTx = null ;
201- do {
202- pstTx = await arweave . createTransaction (
203- { target : holder , quantity } ,
204- wallet
205- ) ;
206- pstTx . addTag ( "Reference-Id" , referenceId ) ;
207- pstTx . addTag ( "Repo" , repoName ) ;
208- pstTx . addTag ( "Version" , "0.0.2" ) ;
209- pstTx . addTag ( "App-Name" , "Gitopia" ) ;
210- pstTx . addTag (
211- "Unix-Time" ,
212- Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( )
213- ) ;
214-
215- await arweave . transactions . sign ( pstTx , wallet ) ;
216- await arweave . transactions . post ( pstTx ) ;
217- } while ( ( await waitTxPropogation ( arweave , pstTx ) ) !== 202 ) ;
207+ const pstTx = await arweave . createTransaction (
208+ { target : holder , quantity } ,
209+ wallet
210+ ) ;
211+ pstTx . addTag ( "Reference-Id" , referenceId ) ;
212+ pstTx . addTag ( "Repo" , repoName ) ;
213+ pstTx . addTag ( "Version" , "0.0.2" ) ;
214+ pstTx . addTag ( "App-Name" , "Gitopia" ) ;
215+ pstTx . addTag ( "Unix-Time" , Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( ) ) ;
216+
217+ await arweave . transactions . sign ( pstTx , wallet ) ;
218+ await arweave . transactions . post ( pstTx ) ;
218219} ;
0 commit comments