2323import java .util .concurrent .TimeUnit ;
2424import java .util .concurrent .atomic .AtomicInteger ;
2525
26- import com .seq .http .session .ProdRefresher ;
27- import com .seq .http .session .Refresher ;
26+ import com .google .gson .annotations .SerializedName ;
2827import com .google .gson .Gson ;
2928
3029import com .squareup .okhttp .CertificatePinner ;
4746 */
4847public class Client {
4948 private OkHttpClient httpClient ;
50- private String macaroon ;
49+ private String credential ;
5150 private String ledgerName ;
52- public Refresher refresher ;
51+ private String teamName ;
52+ private Boolean teamNameRequested ;
5353
5454 // Used to create empty, in-memory key stores.
5555 private static final char [] DEFAULT_KEYSTORE_PASSWORD = "password" .toCharArray ();
@@ -60,6 +60,15 @@ private static class BuildProperties {
6060 public String version ;
6161 }
6262
63+ private static class TeamResponse {
64+ @ SerializedName ("team_name" )
65+ public String teamName ;
66+
67+ public TeamResponse () {
68+ this .teamName = null ;
69+ }
70+ }
71+
6372 static {
6473 InputStream in = Client .class .getClassLoader ().getResourceAsStream ("properties.json" );
6574 if (in != null ) {
@@ -76,9 +85,17 @@ public Client(Builder builder) throws ConfigurationException {
7685 throw new ConfigurationException ("No credential provided" );
7786 }
7887 this .ledgerName = builder .ledger ;
79- this .macaroon = builder .credential ;
88+ this .credential = builder .credential ;
8089 this .httpClient = buildHttpClient (builder );
81- this .refresher = new ProdRefresher ();
90+ this .teamName = null ;
91+ this .teamNameRequested = false ;
92+ }
93+
94+ public void getTeamName (String credential ) throws ChainException {
95+ this .teamNameRequested = true ;
96+ TeamResponse teamResp = new TeamResponse ();
97+ teamResp = request ("hello" , new Object (), TeamResponse .class );
98+ this .teamName = teamResp .teamName ;
8299 }
83100
84101 /**
@@ -98,18 +115,18 @@ public T create(Response response, Gson deserializer) throws IOException {
98115 }
99116 };
100117
101- if (this .refresher . needsRefresh () ) {
102- this . refresher . refresh (this .macaroon );
118+ if (this .teamNameRequested == false && this . teamName == null ) {
119+ getTeamName (this .credential );
103120 }
104121 return post (action , body , rc );
105122 }
106123
107124 /**
108- * Returns the macaroon (possibly null).
109- * @return the macaroon
125+ * Returns the credential (possibly null).
126+ * @return the credential
110127 */
111- public String macaroon () {
112- return macaroon ;
128+ public String credential () {
129+ return credential ;
113130 }
114131
115132 /**
@@ -188,8 +205,10 @@ private <T> T post(String path, Object body, ResponseCreator<T> respCreator)
188205 if (urlParts .endsWith ("/" )) {
189206 urlParts = urlParts .substring (0 , urlParts .length () - 1 );
190207 }
191- urlParts += "/" + this .refresher .teamName ();
192- urlParts += "/" + this .ledgerName ;
208+ if (this .teamName != null ) {
209+ urlParts += "/" + this .teamName ;
210+ urlParts += "/" + this .ledgerName ;
211+ }
193212 urlParts += "/" + path ;
194213 endpointURL = new URL (urlParts );
195214 } catch (MalformedURLException ex ) {
@@ -199,8 +218,7 @@ private <T> T post(String path, Object body, ResponseCreator<T> respCreator)
199218 Request req =
200219 new Request .Builder ()
201220 .header ("User-Agent" , "sequence-sdk-java/" + version )
202- .header ("Macaroon" , this .macaroon )
203- .header ("Discharge-Macaroon" , this .refresher .dischargeMacaroon ())
221+ .header ("Credential" , this .credential )
204222 .header ("Idempotency-Key" , idempotencyKey )
205223 .header ("Name-Set" , "camel|snake" )
206224 .url (endpointURL )
@@ -353,8 +371,8 @@ private Response checkError(Response response) throws ChainException {
353371 @ Override
354372 public int hashCode () {
355373 int code = 0 ;
356- if (this .macaroon != null ) {
357- code = code * 31 + this .macaroon .hashCode ();
374+ if (this .credential != null ) {
375+ code = code * 31 + this .credential .hashCode ();
358376 }
359377 return code ;
360378 }
@@ -370,7 +388,7 @@ public boolean equals(Object o) {
370388 if (!(o instanceof Client )) return false ;
371389
372390 Client other = (Client ) o ;
373- return Objects .equals (this .macaroon , other .macaroon );
391+ return Objects .equals (this .credential , other .credential );
374392 }
375393
376394 /**
0 commit comments